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 2012 Forums
 Transact-SQL (2012)
 delete problem

Author  Topic 

rjhe22
Constraint Violating Yak Guru

283 Posts

Posted - 2014-09-19 : 07:16:07
hi

im trying to delete info from a table.

im trying to delete records from a table that are not equal to comp a or comp t and where the acc number starts with 1 or 2

i tried the following

delete from dbo.SSCUKWorkingGLDataloadFile
where SUBSTRING(AccountCode,1,1) = '2' or SUBSTRING(AccountCode,1,1) = '1'
and ClassLoadCode != 'Comp A' or ClassLoadCode != 'Comp T'


but its deleteing to many out. deletes ones where account number doesnt start with 1 or 2 any ideas why

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2014-09-19 : 07:25:56
quote:
Originally posted by rjhe22

hi

im trying to delete info from a table.

im trying to delete records from a table that are not equal to comp a or comp t and where the acc number starts with 1 or 2

i tried the following

delete from dbo.SSCUKWorkingGLDataloadFile
where (SUBSTRING(AccountCode,1,1) = '2' or SUBSTRING(AccountCode,1,1) = '1')
and (ClassLoadCode != 'Comp A' or ClassLoadCode != 'Comp T')


but its deleteing to many out. deletes ones where account number doesnt start with 1 or 2 any ideas why



Harsh Athalye
http://www.letsgeek.net/
Go to Top of Page

rjhe22
Constraint Violating Yak Guru

283 Posts

Posted - 2014-09-19 : 07:28:30
??
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2014-09-19 : 07:29:32
A better way would be:

delete from dbo.SSCUKWorkingGLDataloadFile
where (AccountCode like '1%' or AccountCode like '2%')
and ClassLoadCode not in ('Comp A','Comp T')


Harsh Athalye
http://www.letsgeek.net/
Go to Top of Page

rjhe22
Constraint Violating Yak Guru

283 Posts

Posted - 2014-09-19 : 07:31:01
will try that tahnks very much
Go to Top of Page
   

- Advertisement -