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 |
|
OldMySQLUser
Constraint Violating Yak Guru
301 Posts |
Posted - 2009-07-22 : 07:28:10
|
| I have a statementdelete from Categorieswhere ID = 5720 and CategoryCode = '0002' ANDCategoryCode = '0003' ANDCategoryCode = '0004' ANDCategoryCode = '0005'is there a more efficient way to handle all the 'AND's please?(CategoryCode is a varchar field) |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-07-22 : 07:30:03
|
| delete from Categorieswhere ID = 5720 and CategoryCode in ('0002' ,'0003' ,'0004' , '0005') |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-07-22 : 07:33:29
|
| DELETE FROM CATEGORIES WHERE ID = 5720 AND '%,' + '0002,0003,0004,0005'+ ',%' LIKE '%,' +CATEGORIES+',%' |
 |
|
|
Mangal Pardeshi
Posting Yak Master
110 Posts |
Posted - 2009-07-22 : 07:47:47
|
Does any row really getting deleted?One column can't satisfy multiple AND conditions... I guess it should be OR instead of AND.quote: Originally posted by OldMySQLUser I have a statementdelete from Categorieswhere ID = 5720 and CategoryCode = '0002' ANDCategoryCode = '0003' ANDCategoryCode = '0004' ANDCategoryCode = '0005'is there a more efficient way to handle all the 'AND's please?(CategoryCode is a varchar field)
Mangal Pardeshihttp://mangalpardeshi.blogspot.com |
 |
|
|
OldMySQLUser
Constraint Violating Yak Guru
301 Posts |
Posted - 2009-07-22 : 08:03:28
|
quote: Originally posted by Mangal Pardeshi Does any row really getting deleted?One column can't satisfy multiple AND conditions... I guess it should be OR instead of AND.quote: Originally posted by OldMySQLUser I have a statementdelete from Categorieswhere ID = 5720 and CategoryCode = '0002' ANDCategoryCode = '0003' ANDCategoryCode = '0004' ANDCategoryCode = '0005'is there a more efficient way to handle all the 'AND's please?(CategoryCode is a varchar field)
Mangal Pardeshihttp://mangalpardeshi.blogspot.com
You are, or course, correct. It should have been or. My bad. |
 |
|
|
|
|
|
|
|