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)
 Delete Query Not Working

Author  Topic 

Looper
Yak Posting Veteran

68 Posts

Posted - 2009-06-23 : 10:59:56
The following query is deleting ALL from the table instead of meeting the criteria in the where clause, can someone advise

DELETE esm
FROM EmpSMed esm
INNER JOIN empt e ON e.Id = esm.EmptId
INNER JOIN EmpSubPay esp ON esp.EmptId = e.Id
WHERE SUBSTRING(esp.Full,4,1) <> 'A' OR SUBSTRING(esp.Full,4,1) <> 'B' OR SUBSTRING(esp.Full,4,1) <> 'C' OR emp.Job <> 'M And D'

Basically if there are rows in table EmpSMed and they do not have A,B or C in 4th character of field Full or field Job is not M and D then delete from table EmpSMed. currently the above query is removing everything from the table.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-06-23 : 11:08:46
the checking of esp.Full should be a AND condition not OR

or you can write it this way
WHERE SUBSTRING(esp.Full,4,1) not in ('A', 'B', 'C' )OR emp.Job <> 'M And D'



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-06-23 : 11:10:05
NOT OR NOT is always true!
Because
when esp.full,4,1 is B then SUBSTRING(esp.Full,4,1) <> 'A' is true
when esp.full,4,1 is A then SUBSTRING(esp.Full,4,1) <> 'B' is true and so on...

I believe you mean AND.

What is this? OR emp.Job <> 'M And D' ??

Webfred


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-06-23 : 11:10:44
again tooooooooooooo late


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Looper
Yak Posting Veteran

68 Posts

Posted - 2009-06-23 : 11:22:59
Thanks that worked.

Go to Top of Page
   

- Advertisement -