I am attempting to get the OUTPUT table from an INSERT command on a SQL Server database (v14).
DECLARE @i TABLE (TICKET_ID int, CREATED_DATE datetime);
INSERT INTO dbo.TICKET (SITE_ID, TICKET_TITLE, USER_ID)
OUTPUT INSERTED.TICKET_ID, INSERTED.CREATED_DATE INTO @i
VALUES (@s, @t, @q);
SELECT * FROM @i;
I have 3 parameters that are being populated for the site, ticket title and user by @s, @t and @u respectively.
I am calling the command using a SqlClient.SqlDataReader Object with ExecuteReader Function on the 4.5 Framework.
The command successfully inserts the record into the database table, but does not return the table @i with the ticket ID (Auto Increment) and created date (default =GETDATE) which is what I am expected to present to the user once saved to the database.
I have played around with the removing of the @i TABLE in the command, but I get a .NET error:
The target table 'name' of the DML statement cannot have any enabled triggers if the statement contains an OUTPUT clause without INTO clause
I have found a couple of links that provide some ways to fix these but it did not fix my issue
Cannot use UPDATE with OUTPUT clause when a trigger is on the table
Is there any assistance that can be provided to assist in what I am trying to achieve?