SQL SERVER:
Using coalesce to concatenate a series of strings from a record in a table
Select Statement.
Simple coalesce Statement
declare @Temp varchar (200)
set @Temp = ''
select @Temp =
case when @Temp = ''
then ''''+ stateName + ''''
else @Temp + coalesce(',''' + stateName + '''', '')
end
from state
print @Temp
Result:
declare @Temp varchar (200)
set @Temp = ''
select @Temp =
case when @Temp = ''
then ''''+ stateName + ''''
else @Temp + coalesce(',''' + stateName + '''', '')
end
from state
print @Temp
MYSQL:
Try this.
Using GROUP_CONCAT to concatenate a series of strings from a record in a table
SELECT GROUP_CONCAT(concat('''',state,'''')) AS List
FROM state;
Result:
Try this.
Using GROUP_CONCAT to concatenate a series of strings from a record in a table
SELECT GROUP_CONCAT(concat('''',state,'''')) AS List
FROM state;
Result:
0 Comments