MadIce
asked on
T-SQL setup String
I pass a string to my stored procedure that can be setup in different formats. I trying to use Trim, replace, CharIndex and such to format it in a way I can use. Here is what the string usually looks like when passing:
'Widget1, Widget2, Widget3
Widget4, Widget5, Widget6
Widget7, Widget'
It might be hard to tell from this but say after Widget3 there are a bunch of spaces. This is what I need the string to look like:
'Widget1, Widget2, Widget3, Widget4, Widget5, Widget6, Widget7, Widget8'
so a coma after each widget or remove all comma and have one single space. either would work
'Widget1, Widget2, Widget3
Widget4, Widget5, Widget6
Widget7, Widget'
It might be hard to tell from this but say after Widget3 there are a bunch of spaces. This is what I need the string to look like:
'Widget1, Widget2, Widget3, Widget4, Widget5, Widget6, Widget7, Widget8'
so a coma after each widget or remove all comma and have one single space. either would work
ASKER
That removes the spaces but how do I add the missing comas?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I have this so far
SET @Parameters = LTRIM(RTRIM(@Parameters))+ ','
set @Parameters = replace(@Parameters, ' ', '')
set @Parameters = replace(@Parameters, CHAR(10), ',')
Problem is it puts the coma on the next row as oppose to next to the "Widget". like this
'Widget1, Widget2, Widget3
,Widget4,
SET @Parameters = LTRIM(RTRIM(@Parameters))+
set @Parameters = replace(@Parameters, ' ', '')
set @Parameters = replace(@Parameters, CHAR(10), ',')
Problem is it puts the coma on the next row as oppose to next to the "Widget". like this
'Widget1, Widget2, Widget3
,Widget4,
ASKER
Didn't see your last comment. That works. Thanks
SET @Parameters = Replace(Replace(Replace(Re place(Repl ace(Replac e(Replace( Replace(LT RIM(RTRIM( @Parameter s)), ',', ' '), char(13), ' '), char(10), ' '), ' ', ' '), ' ', ' '), ' ', ' '), ' ', ' '), ' ', ', ')
use REPLACE
SET @Parameter = REPLACE(@Parameter, ' ', '')