Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 delete

Author  Topic 

vicki
Posting Yak Master

117 Posts

Posted - 2002-11-22 : 10:19:56
Hi guys,

I have the store procedure to delete a a record from a table, and I want to delete more than one record at the time but don't know how. The one I have now just delete one at the time

Delete tbl1
from tbl1 join tbl2
On tbl1.id=tbl2.id
Where tbl2.userid = @userid


mr_mist
Grunnio

1870 Posts

Posted - 2002-11-22 : 10:21:49

What is the criteria to choose if a name should be deleted or not?



-------
Moo.
Go to Top of Page

ValterBorges
Master Smack Fu Yak Hacker

1429 Posts

Posted - 2002-11-22 : 10:23:02
Specify your criteria.

Go to Top of Page

vicki
Posting Yak Master

117 Posts

Posted - 2002-11-22 : 10:34:05
quote:


What is the criteria to choose if a name should be deleted or not?



-------
Moo.



Criteria la id like 1,2,3......

Go to Top of Page

vicki
Posting Yak Master

117 Posts

Posted - 2002-11-22 : 10:34:30
quote:

Specify your criteria.





Criteria la userid like 1,2,3......

Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2002-11-22 : 10:48:34
dynamic sql

declare @sql varchar(1000)
select @sql = 'delete tbl1
from from tbl1 join tbl2
On tbl1.id=tbl2.id
Where tbl2.userid in (' + @userids + ')'
exec (@sql)

or a like statement
delete tbl1
from from tbl1 join tbl2
On tbl1.id=tbl2.id
Where ',' + @userids + ',' like '%,' + tbl2.userid + ',%'

or parse the csv string, put the values into a temp table or table variable and join to that.

Have a search on the site for csv - there have been quite a few threads about it.


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -