Rate this:
See more:
I want to split a string 123test\$%^ into different parts based on their type. Can any one help me.
Posted 13-Dec-12 23:34pm
OriginalGriff at 14-Dec-12 4:36am

This is not a good question - we cannot work out from that little what you are trying to do.
Use the "Improve question" widget to edit your question and provide better information.

Rate this:

Rate this:

## Solution 3

Try SUBSTRING or RIGHT or LEFT; just check out the STRING functions for starters
```
DECLARE @frastr [nvarchar](128), @dmyndlstr[nvarchar](128), @nfrnchsint [int], @dracint [int]
SET @frastr = '123Test\$%^'
SET @dmyndlstr = ''
SET @nfrnchsint = LEN(@frastr)
SET @dracint = 0

WHILE @dracint < @nfrnchsint + 1
BEGIN
SET @dmyndlstr = SUBSTRING(@frastr,0,@nfrnchsint + 1)
PRINT @dmyndlstr
SET @nfrnchsint = @nfrnchsint -1
END
```
Or another SUBSTRING
```DECLARE @frastr [nvarchar](128), @dmyndlstr[nvarchar](128), @nfrnchsint [int], @dracint [int]
SET @frastr = '123Test\$%^'
SET @dmyndlstr = ''
SET @nfrnchsint = LEN(@frastr)
SET @dracint = 0

WHILE @dracint < @nfrnchsint + 2
BEGIN
SET @dmyndlstr = SUBSTRING(@frastr,0,LEN(@frastr)-@nfrnchsint)
PRINT @dmyndlstr
SET @nfrnchsint = @nfrnchsint -1
END
```
Or a LEFT and a RIGHT
```DECLARE @frastr [nvarchar](128), @dmyndlstr[nvarchar](128), @nfrnchsint [int], @dracint [int]
SET @frastr = '123Test\$%^'
SET @dmyndlstr = ''
SET @nfrnchsint = LEN(@frastr)
SET @dracint = 0

WHILE @dracint < @nfrnchsint
BEGIN
SET @dmyndlstr = LEFT(@frastr,1)
PRINT @dmyndlstr
SET @frastr = RIGHT(@frastr,@nfrnchsint-1)
SET @nfrnchsint = @nfrnchsint -1
END

```
v3