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 question

Author  Topic 

OldMySQLUser
Constraint Violating Yak Guru

301 Posts

Posted - 2009-07-23 : 06:31:49
I am using

USE debt
GO

/* Change Categories */

declare @cnt int

delete

FROM DebtorCategories AS dc
JOIN Debtor AS dtr
ON dtr.DebtorID = dc.DebtorID
JOIN TraceOutputTemp AS tmp
ON dt.Code = tmp.Ref

where tmp.Ref = dt.code AND
tmp.DebtorNo = dtr.DebtorNo AND
dc.DebtorCategoryCode in ('0002' ,'0003' ,'0004' , '0005')

GO

but SQL complains with 'incorrect syntax near the keyword AS'.
I cannot see why this should be.

Any ideas appreciated.

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-07-23 : 06:33:02
delete dc
FROM DebtorCategories AS dc
JOIN Debtor AS dtr
ON dtr.DebtorID = dc.DebtorID
JOIN TraceOutputTemp AS tmp
ON dt.Code = tmp.Ref
where tmp.Ref = dt.code AND
tmp.DebtorNo = dtr.DebtorNo AND
dc.DebtorCategoryCode in ('0002' ,'0003' ,'0004' , '0005')

Go to Top of Page

OldMySQLUser
Constraint Violating Yak Guru

301 Posts

Posted - 2009-07-23 : 06:42:38
Thanks for the reply.
But, what exactly was the error I made please. (My brain really is not functioning today at all)
Go to Top of Page

asafg
Starting Member

39 Posts

Posted - 2009-07-23 : 07:44:24
you told the sql
which tables are relevant in the from part
you said what qualifies records that should be deleted in the where part

so you have a list of rows that qualify for deletion

but from where?

Delete X
FROM

X is the table from which rows will be removed... follow OldMySQLUser code... it's nice and simple
Go to Top of Page
   

- Advertisement -