Delete Multiple Integers as Parameter from an Int Column



--Delete multiple Integers as Parameter from an Int column
create proc deleteValues 
@IDS varchar(100)
as
delete Info where charindex( ','+ CAST(ID as varchar(5))+',' ,','+@IDS+',')>0
go

create table info (id int, col int)
Insert into info values(1,1),(2,1),(5,1),(6,1),(7,1),(8,1),(9,1),(3,1)

declare @s varchar(100)
set @s='5,6,7,8'
exec deletevalues @s
go
select * from info

--Clean up
drop table info
drop procedure deleteValues

Another way is to use either a UDF Split function or an inline XML splitter

to extract individual ID to use in the query.

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s