How to use insert and select simultaneously? 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?
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);