Tuesday, November 22, 2005

SQL: not so handy function

I ran into a strange situation today. I need to make a comma seperated list of values in tsql here is what I came up with

declare @cycles varchar(8000)
set @cycles = ''
SELECT @cycles = @cycles + CAST(producer_cycle_id AS varchar(100)) + ', '

from cycles

Note that this function does not work very with nulls (hence why @cycles is initialized to ''. If you have null data make sure you have an isnull() in their to convert it!


Post a Comment

<< Home