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.
| 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 deleteHere the sp i use i am not sure if it possible that way?It not working right now is there someting i can change?Tksquote: 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 +',%' |
 |
|
|
lucsky8
Posting Yak Master
105 Posts |
Posted - 2012-01-10 : 08:47:21
|
Hi tks for the responseI don t think the like would work this situation because it seperate idIn my .net each checkbox is bind to the unique ID i need to deleteCan you show me the link by Pesi please?tksquote: 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 +',%'
|
 |
|
|
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 saidtksquote: 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 +',%'
|
 |
|
|
lucsky8
Posting Yak Master
105 Posts |
Posted - 2012-01-10 : 08:57:11
|
| If my variable return something like this 1,5,9,15How can i split them is SQL so i can delete the row 1, 5, 9 and 15 by row i mean the idTks |
 |
|
|
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,15How can i split them is SQL so i can delete the row 1, 5, 9 and 15 by row i mean the idTks
you need to use a tring parsing function like below http://visakhm.blogspot.com/2010/02/parsing-delimited-string.html------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2012-01-10 : 09:33:32
|
| Try the code posted by Sunita. It will work as expectedMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|