Guest User

Untitled

a guest
Nov 21st, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. DECLARE @position INT;
  2. DECLARE @string VARCHAR(max);
  3.  
  4. SET @string = '9FX8173';
  5.  
  6. WHILE 1 = 1
  7. BEGIN
  8. SET @position = (SELECT Min(position)
  9. FROM (VALUES (Patindex('%[^''0-9][0-9]%', @string)),
  10. (Patindex('%[0-9][^''0-9]%', @string))) AS T(position)
  11. WHERE T.position > 0);
  12.  
  13. IF @position IS NULL
  14. BREAK;
  15.  
  16. SET @string = Stuff(@string, @position + 1, 0, '''');
  17. END
  18.  
  19. PRINT @string;
  20.  
  21. SET @string = 'PAYGA0102'
  22.  
  23. WHILE 1 = 1
  24. BEGIN
  25. SET @position = (SELECT Min(position)
  26. FROM (VALUES (Patindex('%[^''0-9][0-9]%', @string)),
  27. (Patindex('%[0-9][^''0-9]%', @string))) AS T(position)
  28. WHERE T.position > 0);
  29.  
  30. IF @position IS NULL
  31. BREAK;
  32.  
  33. SET @string = Stuff(@string, @position + 1, 0, '''');
  34. END
  35.  
  36. PRINT @string;
  37.  
  38. SET @string = '00086K'
  39.  
  40. WHILE 1 = 1
  41. BEGIN
  42. SET @position = (SELECT Min(position)
  43. FROM (VALUES (Patindex('%[^''0-9][0-9]%', @string)),
  44. (Patindex('%[0-9][^''0-9]%', @string))) AS T(position)
  45. WHERE T.position > 0);
  46.  
  47. IF @position IS NULL
  48. BREAK;
  49.  
  50. SET @string = Stuff(@string, @position + 1, 0, '''');
  51. END
  52.  
  53. PRINT @string;
  54.  
  55. SET @string = 'ADEP'
  56.  
  57. WHILE 1 = 1
  58. BEGIN
  59. SET @position = (SELECT Min(position)
  60. FROM (VALUES (Patindex('%[^''0-9][0-9]%', @string)),
  61. (Patindex('%[0-9][^''0-9]%', @string))) AS T(position)
  62. WHERE T.position > 0);
  63.  
  64. IF @position IS NULL
  65. BREAK;
  66.  
  67. SET @string = Stuff(@string, @position + 1, 0, '''');
  68. END
  69.  
  70. PRINT @string;
Add Comment
Please, Sign In to add comment