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
 General SQL Server Forums
 New to SQL Server Programming
 Delete query

Author  Topic 

lucsky8
Posting Yak Master

105 Posts

Posted - 2012-01-10 : 08:29:45
Hi,

I have a radgrid each row have a checkbox so i can select multiple row and delete them.

I have vavariable in .net that return each row the user selected.

Ex:

_toDelete = '1','3','8'

1,3 and 8 is the ID of the item i want to delete

Here the sp i use i am not sure if it possible that way?
It not working right now is there someting i can change?
Tks

quote:

DECLARE @intInventaireId varchar(100)

DELETE FROM dbo.tblInventaireNew
where strSticker IN(SELECT strSticker FROM tblInventaireNew WHERE strSticker IN (@intInventaireId));

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-01-10 : 08:41:09
SQL does not like that. You have couple of alternatives. One is to split the comma-separated string into individual ID's and then delete. Take a look at this page; it has a function written by Peso that will let you do the splitting.

Another way is to use a like clause as in:
DELETE FROM dbo.tblInventaireNew 
WHERE ','+CAST(@intInventaireId AS VARCHAR(32))+',' LIKE '%,'+strSticker +',%'
Go to Top of Page

lucsky8
Posting Yak Master

105 Posts

Posted - 2012-01-10 : 08:47:21
Hi tks for the response

I don t think the like would work this situation because it seperate id
In my .net each checkbox is bind to the unique ID i need to delete
Can you show me the link by Pesi please?
tks

quote:
Originally posted by sunitabeck

SQL does not like that. You have couple of alternatives. One is to split the comma-separated string into individual ID's and then delete. Take a look at this page; it has a function written by Peso that will let you do the splitting.

Another way is to use a like clause as in:
DELETE FROM dbo.tblInventaireNew 
WHERE ','+CAST(@intInventaireId AS VARCHAR(32))+',' LIKE '%,'+strSticker +',%'


Go to Top of Page

lucsky8
Posting Yak Master

105 Posts

Posted - 2012-01-10 : 08:49:39
I will try to split them in sql and delete the like you said

tks

quote:
Originally posted by sunitabeck

SQL does not like that. You have couple of alternatives. One is to split the comma-separated string into individual ID's and then delete. Take a look at this page; it has a function written by Peso that will let you do the splitting.

Another way is to use a like clause as in:
DELETE FROM dbo.tblInventaireNew 
WHERE ','+CAST(@intInventaireId AS VARCHAR(32))+',' LIKE '%,'+strSticker +',%'


Go to Top of Page

lucsky8
Posting Yak Master

105 Posts

Posted - 2012-01-10 : 08:57:11
If my variable return something like this

1,5,9,15

How can i split them is SQL so i can delete the row 1, 5, 9 and 15 by row i mean the id

Tks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-10 : 09:27:06
quote:
Originally posted by lucsky8

If my variable return something like this

1,5,9,15

How can i split them is SQL so i can delete the row 1, 5, 9 and 15 by row i mean the id

Tks


you need to use a tring parsing function like below

http://visakhm.blogspot.com/2010/02/parsing-delimited-string.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2012-01-10 : 09:33:32
Try the code posted by Sunita. It will work as expected

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -