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 2005 Forums
 Transact-SQL (2005)
 Query efficiency

Author  Topic 

OldMySQLUser
Constraint Violating Yak Guru

301 Posts

Posted - 2009-07-22 : 07:28:10
I have a statement

delete from Categories
where ID = 5720 and
CategoryCode = '0002' AND
CategoryCode = '0003' AND
CategoryCode = '0004' AND
CategoryCode = '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 Categories
where ID = 5720 and
CategoryCode in ('0002' ,'0003' ,'0004' , '0005')
Go to Top of Page

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+',%'
Go to Top of Page

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 statement

delete from Categories
where ID = 5720 and
CategoryCode = '0002' AND
CategoryCode = '0003' AND
CategoryCode = '0004' AND
CategoryCode = '0005'

is there a more efficient way to handle all the 'AND's please?
(CategoryCode is a varchar field)



Mangal Pardeshi
http://mangalpardeshi.blogspot.com
Go to Top of Page

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 statement

delete from Categories
where ID = 5720 and
CategoryCode = '0002' AND
CategoryCode = '0003' AND
CategoryCode = '0004' AND
CategoryCode = '0005'

is there a more efficient way to handle all the 'AND's please?
(CategoryCode is a varchar field)



Mangal Pardeshi
http://mangalpardeshi.blogspot.com



You are, or course, correct. It should have been or. My bad.
Go to Top of Page
   

- Advertisement -