September 3, 2013 at 12:39 pm
Hello Everyone
I need to develop something in my logic. I have one code '7MTWRF', this is string and i need to convert as
M:7;T:7;W:7;R:7;F:7
please help me to do so
Thanks
September 3, 2013 at 12:51 pm
This can't be as simple as it appears, so I have to question what is missing. If it really is this simple, just use the SUBSTRING function to concatenate the string you want to return back.
September 3, 2013 at 1:07 pm
As Ed said, this might be more complicated than this. However, this might give you an idea on what you need.
WITH CTE( String) AS(
SELECT '7MTWRF'
),
Tally AS(
SELECT TOP 100 ROW_NUMBER() OVER( ORDER BY (SELECT NULL)) n
FROM sys.objects
),
OneString( String) AS(
SELECT ';' + SUBSTRING(String,n,1) + ':' + LEFT( String, 1)
FROM CTE c
JOIN Tally t ON LEN(c.String) >= n
WHERE n > 1
FOR XML PATH('')
)
SELECT STUFF(String, 1, 1, '')
FROM OneString
Check the following reference: Creating a comma-separated list[/url]
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply