Problem with OUTPUT Clause

I'm having trouble with the following code.  When I execute it, I get the following error:

Msg 207, Level 16, State 1, Line 42
Invalid column name '$ACTION'.
Msg 8101, Level 16, State 1, Line 41
An explicit value for the identity column in table '#Audit' can only be specified when a column list is used and IDENTITY_INSERT is ON.


Any Ideas?

I'm Running:
SQL Server 2008 (10.0.1600)
Windows XP Professional SP3

Thanks,
Letron
--Illustrate use of OUTPUT clause on INSERT, UPDATE, and DELETE statements
--04/20/2010
USE WorkSampleDatabase
GO

--Create Checking Account table
IF OBJECT_ID(N'tempdb..#Checking') IS NOT NULL
	DROP TABLE #Checking
	
CREATE TABLE #Checking
(
	CheckingID INT IDENTITY(1,1)
	,FName NVARCHAR(30)
	,LName NVARCHAR(30)
	,Amount DECIMAL(18,2)
)

--Create Savings Account table
IF OBJECT_ID(N'tempdb..#Saving') IS NOT NULL
	DROP TABLE #Saving
	
CREATE TABLE #Saving
(
	SavingID INT IDENTITY(1,1)
	,FName NVARCHAR(30)
	,LName NVARCHAR(30)
	,Amount DECIMAL(18,2)
)

--Create Audit table
IF OBJECT_ID(N'tempdb..#Audit') IS NOT NULL
	DROP TABLE #Audit
	
CREATE TABLE #Audit
(
	AuditID INT IDENTITY(1,1)
	,RowAction NVARCHAR(20)
	,TableName NVARCHAR(10)
	,RowID INT
	,OldAmount DECIMAL(18,2)
	,NewAmount DECIMAL(18,2)
	,InsertDate DATETIME
)

INSERT INTO #Checking (FName,LName,Amount)
	OUTPUT $ACTION,'#Checking',INSERTED.CheckingID,NULL,INSERTED.Amount,GETDATE() INTO #Audit
	VALUES ('Blake','Johnson',2000.40)
	      ,('Bill','Watkins',3235.15)
	      ,('Edwin','Hawkins',210.00)
	      ,('Rosa','Hemphill',10032.03)
	
SELECT * FROM #Checking
SELECT * FROM #Audit

Open in new window

ltrain2015Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

HainKurtSr. System AnalystCommented:
$action

Is available only for the MERGE statement. Specifies a column of type nvarchar(10) in the OUTPUT clause in a MERGE statement that returns one of three values for each row: 'INSERT', 'UPDATE', or 'DELETE', according to the action that was performed on that row.

--> http://msdn.microsoft.com/en-us/library/ms177564.aspx

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ltrain2015Author Commented:
Hmmm... That's a drag.  I'll have to find another way.

Thanks!

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.