Last active
April 29, 2019 21:04
-
-
Save sqldeployhelmet/912959acaf452fc7105b4058555cec6d to your computer and use it in GitHub Desktop.
Converting an NVARCHAR to VARCHAR for fun and profit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Preface the string with N or | |
SQL will pre-emptively destroy | |
the data before storing the string */ | |
DECLARE @nv AS NVARCHAR(10) = N'╥«┘{║‼℈≠' | |
, @v AS VARCHAR(10); | |
SELECT @nv, CAST(@nv AS VARCHAR(10)); | |
/* And by reassigning we can see | |
the data is permanently lost */ | |
SELECT @v = @nv; | |
SELECT @v, CAST(@v AS NVARCHAR(10)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment