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 2000 Forums
 Transact-SQL (2000)
 recursive delete

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-02-27 : 12:00:20
corrado100 writes "Hi there,
Im trying to delete parent child rows that are all in one table called Messages. There is a field MsgID(the ID of the message) and a field ParentID(which MsgID this belongs to). My SQL string looks like this >>

"DELETE FROM Messages M1 JOIN Messages M2 ON M1.MsgID = M2.ParentID WHERE M1.MsgID ='" & Request.Form("MsgID") & "'"

But I get this error>>

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near 'M1'.

Can anyone please help?

Bob."

Kristen
Test

22859 Posts

Posted - 2006-02-27 : 13:11:32
Hi corrado100, Welcome to SQL Team!

You need:

DELETE XXXX FROM Messages M1 JOIN Messages M2 ON M1.MsgID = M2.ParentID WHERE M1.MsgID ='" & Request.Form("MsgID") & "'"

so that SQL Server knows which of your two aliased tables, M1 and M2, to delete from. (XXXX should be either M1 or M2, whichever is the table you want to delete from)

Kristen
Go to Top of Page
   

- Advertisement -