cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

Using OUTPUT in SQL Command

jensc
17-Peridot

Using OUTPUT in SQL Command

Hello,

 

I wanted to use the "OUTPUT" clause in an SQL command to get the latest inserted row.

However I am getting this error: 

Execute Update failed: com.microsoft.sqlserver.jdbc.SQLServerException: A result set was generated for update.

 

Now, the SQL that i am using does work in SSMS. Here is the structure:

 

 

 

INSERT INTO Table
(value1, value2)
OUTPUT Inserted.uid
values(1,2)

 

Any ideas?

 

I would if possible like to avoid using stored procedures.

 

Thanks,

1 ACCEPTED SOLUTION

Accepted Solutions

Use service type as "Query" as following,

Sathishkumar_C_0-1672721873201.png

 

View solution in original post

4 REPLIES 4
dgg
11-Garnet
11-Garnet
(To:jensc)

Try using a table variable to capture the identity column value for the newly inserted row:

declare @uid int;
declare @tableOut table(uid int);

insert into SOMETABLE (
FIRST_NAME,
LAST_NAME output
INSERTED.UID into @tableOut values (
'Neil',
'Peart'
); select @uid = uid from @tableOut;

 

hope that helps,

dgg

Use service type as "Query" as following,

Sathishkumar_C_0-1672721873201.png

 

Hello,

 

I was under the assumption that insert/update/delete only worked using the "command" type of SQL on TWX.

This is exactly what I was looking for!

 

Thanks,

Jens

jensc
17-Peridot
(To:dgg)

Hello,

 

While it gives me what I wanted, it is a bit more convoluted then I would have hoped.

Satish Kumars response works as well and is perhaps easier to understand.

 

Thanks, 

Jens 

Top Tags