Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String Manipulate in Stored Procedures

Status
Not open for further replies.

JohnPham

Programmer
Jul 9, 2001
34
US
Hi All,

Any one have any idea how to make this work. I have a tring for example: "ABC, CDG, DGT" When I pass this to Stored Procedures as parameter, How do I make it looks like:
"('ABC', 'CDG', 'DGT')"

Thanks,

John
 
To make it easier, the first thing I would do is do a replace any white space on the string:

select @var = 'ABC, CDG, DGT'

select @var = replace(@var, ', ', ',')

So now you have: 'ABC,CDG,DGT'

This will get you started:

while patindex('%,%', @var ) != 0

begin

print left(@var , patindex('%,%', @var) - 1))

select @var = right(@var, len(@var)-patindex('%,%',(@var))

end

print @var

Craig
 
Hi,

Try this

Select '''' + replace('ABC, CDG, DGT', ', ', ''',''') + ''''

hope it helps....

Sunil
 
Sunil/Craig

Thank you very much. This help a lot.

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top