i need to convert the following values from a variable:
1234,1234,12345,12346,1344,4564
to this:
'1234','1234','12345','12346','1344','4564'
using an SQL function.
I have tried:
DECLARE @VAL AS VARCHAR(MAX)
SELECT @VAL = '1234,1234,12345,12346,1344,4564'
DECLARE @listStr VARCHAR(MAX)
SELECT @listStr = COALESCE(@listStr+',' ,'') + @VAL
SELECT @listStr AS 'List'
GO
But i get:
1234,1234,12345,12346,1344,4564
select '''' + replace(@yourvariable,',',''',''') + ''''varchar(max), it's intended for use as a BLOB, not as a convenient string without size@listStrinto something likeWHERE column IN (' + @listStr + ')? You really should look into table-valued parameters or, if you are on < 2008, splitting strings.