daily pastebin goal
68%
SHARE
TWEET

Untitled

SQLSoldier Mar 16th, 2015 205 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. WITH Chars (MaxLen)
  2. AS (SELECT MAX(len(name))
  3.         FROM sys.DATABASES),
  4. FixBadChars
  5. AS (SELECT CAST(name AS nvarchar(1000)) AS FixedString, 1 AS MyChar
  6.         FROM sys.DATABASES
  7.         UNION ALL
  8.         SELECT CASE WHEN Unicode(SUBSTRING(FixedString, MyChar + 1, 1)) > 255 THEN
  9.         CAST(Stuff(FixedString, MyChar + 1, 1, N'') AS nvarchar(1000))
  10.                 ELSE FixedString
  11.                 END AS FixedString, MyChar + 1
  12.         FROM FixBadChars
  13.         CROSS Apply Chars
  14.         WHERE MyChar <= MaxLen)
  15. SELECT FixedString
  16. FROM FixBadChars
  17. CROSS Apply Chars
  18.         WHERE MyChar = MaxLen
  19. OPTION (MAXRECURSION 8000)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top