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 2008 Forums
 Transact-SQL (2008)
 OUTPUT Clause with Delete statement

Author  Topic 

evanburen
Posting Yak Master

167 Posts

Posted - 2011-08-19 : 11:38:47
Hi

I'm not sure why I'm getting this error

Msg 156, Level 15, State 1, Line 10
Incorrect syntax near the keyword 'DELETE'.
Msg 102, Level 15, State 1, Line 16
Incorrect syntax near ')'.

INSERT dbo.CustomersInactive (
CustomerID,
FirstName,
LastName
) SELECT
CustomerID,
FirstName,
Lastname
FROM (
DELETE dbo.CustomersActive
OUTPUT
DELETED.CustomerID,
DELETED.FirstName,
DELETED.LastName
WHERE CustomerID IN ( 1001, 1003, 1005 )
) AS RowsToMove

SELECT * FROM dbo.CustomersActive
SELECT * FROM dbo.CustomersInactive

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-19 : 12:03:38
[code]
INSERT dbo.CustomersInactive (
CustomerID,
FirstName,
LastName
) SELECT
CustomerID,
FirstName,
Lastname
FROM (
DELETE dbo.CustomersActive
OUTPUT
DELETED.CustomerID,
DELETED.FirstName,
DELETED.LastName
WHERE CustomerID IN ( 1001, 1003, 1005 )
) AS RowsToMove (CustomerID,FirstName,lastName)
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-19 : 12:35:02
b/w are you using correct compatibility level? it should be 100 or above

check it first

sp_dbcmptlevel 'database name here'

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -