Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DECLARE @position INT;
- DECLARE @string VARCHAR(max);
- SET @string = '9FX8173';
- WHILE 1 = 1
- BEGIN
- SET @position = (SELECT Min(position)
- FROM (VALUES (Patindex('%[^''0-9][0-9]%', @string)),
- (Patindex('%[0-9][^''0-9]%', @string))) AS T(position)
- WHERE T.position > 0);
- IF @position IS NULL
- BREAK;
- SET @string = Stuff(@string, @position + 1, 0, '''');
- END
- PRINT @string;
- SET @string = 'PAYGA0102'
- WHILE 1 = 1
- BEGIN
- SET @position = (SELECT Min(position)
- FROM (VALUES (Patindex('%[^''0-9][0-9]%', @string)),
- (Patindex('%[0-9][^''0-9]%', @string))) AS T(position)
- WHERE T.position > 0);
- IF @position IS NULL
- BREAK;
- SET @string = Stuff(@string, @position + 1, 0, '''');
- END
- PRINT @string;
- SET @string = '00086K'
- WHILE 1 = 1
- BEGIN
- SET @position = (SELECT Min(position)
- FROM (VALUES (Patindex('%[^''0-9][0-9]%', @string)),
- (Patindex('%[0-9][^''0-9]%', @string))) AS T(position)
- WHERE T.position > 0);
- IF @position IS NULL
- BREAK;
- SET @string = Stuff(@string, @position + 1, 0, '''');
- END
- PRINT @string;
- SET @string = 'ADEP'
- WHILE 1 = 1
- BEGIN
- SET @position = (SELECT Min(position)
- FROM (VALUES (Patindex('%[^''0-9][0-9]%', @string)),
- (Patindex('%[0-9][^''0-9]%', @string))) AS T(position)
- WHERE T.position > 0);
- IF @position IS NULL
- BREAK;
- SET @string = Stuff(@string, @position + 1, 0, '''');
- END
- PRINT @string;
Add Comment
Please, Sign In to add comment