Sql Concatenating Column Values into a Comma-Separated List| Sql Column Values into a single quote values.|Mysql Column Values into a single quote values.

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:

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:

Post a Comment

0 Comments