Skip to content

Instantly share code, notes, and snippets.

@sqldeployhelmet
Last active April 29, 2019 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sqldeployhelmet/912959acaf452fc7105b4058555cec6d to your computer and use it in GitHub Desktop.
Save sqldeployhelmet/912959acaf452fc7105b4058555cec6d to your computer and use it in GitHub Desktop.
Converting an NVARCHAR to VARCHAR for fun and profit
/* 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