Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi All,
I want to format string in sql. i am not sure is it possible like regex in sql
SQL
Declare @size Varchar(500)
SET @size = 'X,M,L,XL,XXL'

I want Output like = '0,0,0,0,0'
if size = 'X,M,L' Then Output = '0,0,0'

Thanks
Posted
Comments
Herman<T>.Instance 15-Sep-11 8:09am    
have you searched google?
HinaMehta 15-Sep-11 10:05am    
Can you pls explain it more?What should be the output if the size is :'X,M,L,XL,XXL"?
Chris Meech 15-Sep-11 14:28pm    
For the size variable, isn't it to be 'S,M,L,XL,XXL'? Is this a question about T-Shirt inventory?

1 solution

have you look into (CASE WHEN THEN ELSE END)?

SELECT (CASE WHEN ColumnName='0,0,0,0' THEN 'X,M,L' else '?????' end) as OutputResult from TableName

Good Luck
Al
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900