Carlo Romagnano - Tuesday, November 6, 2018 6:13 AM
I wouldn't exactly recommend using UNCOMPRESS as it seems to only work for VARCHAR, not NVARCHAR:
SELECT UNCOMPRESS(CONVERT(VARBINARY(MAX), 'Hello')),
UNCOMPRESS(CONVERT(VARBINARY(MAX), N'Bye'));
-- Hello B
SELECT CONVERT(VARCHAR(MAX), CONVERT(VARBINARY(MAX), 'Hello')),
CONVERT(NVARCHAR(MAX), CONVERT(VARBINARY(MAX), N'Bye'));
-- Hello Bye
As you can see, the UNCOMPRESS in the first query, when given Unicode data, cuts off after the first character because the "B" is 0x4200 instead of just 0x42. And the 0x00 is the null-terminator for strings, so it stops there.
It also seems kinda silly that UNCOMPRESS even exists given that it only saves typing of 1 word: UNCOMPRESS vs CONVERT(VARCHAR(...).
Take care, Solomon..
SQL# — https://SQLsharp.com/ ( SQLCLR library ofover 340 Functions and Procedures)
Sql Quantum Lift — https://SqlQuantumLift.com/ ( company )
Sql Quantum Leap — https://SqlQuantumLeap.com/ ( blog )
Info sites — Collations • Module Signing • SQLCLR