Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

Query SQL per trasformare una colonna di numeri in una stringa

declare @List varchar(max)

select @List = isnull(@List + ',', '') + cast(ColumnName as varchar)
from MyTable

print @List

Ad esempio:

declare @List varchar(max)

select @List = isnull(@List + ',', '') + cast(object_id as varchar)
from sys.objects

print @List

o

select stuff(
    (select ',' + cast(object_id as varchar)
    from sys.objects
    for xml path('')),
    1, 1, '')