2

I have table test and it has columns id,name and age.I want the id so I am querying like it

select id from test where age=12

After I get the id I am updating the name using update query

Now lets say if age=13 not present then I will insert a row(insert into test(age) values(13)) and after it is inserted I will get the id(as id is autoincremented).So is it possible to do insert and select simultaneously?

0

1 Answer 1

2

So is it possible to do insert and select simultaneously?

Yes, you can use the output clause of the insert statement.

insert into dbo.Test(age) 
output inserted.ID 
values(13); 
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.