Tuesday, October 2, 2007

MS SQL server: Split up a string

CREATE PROCEDURE apPublicationUnselected (@PKPublicationID varChar (255)) AS
set nocount on

declare @sql varchar(8000)

create table #tmp (tmp_id int)

set @sql = 'insert #tmp select ' + replace(@PKPublicationID, ',', ' union select ')
exec (@sql)

SELECT *
FROM tblPublication
WHERE fkproductid Not in (select tmp_id from #tmp)

drop table #tmp

go

No comments: