Hi,
I am trying to get last inserted record in Table on REMOTE SERVER.
I tried using ident_current, SCOPE_IDENTITY() and @@Identity but none of them worked.
Can anyone tell me how to get it??
Thanks in advance.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Anil KumarPosted May 26, 2012, 10:19 PM
Anil KumarPosted May 24, 2012, 1:17 PM
The scope is current context ie local server and it is not remote server. And that is the reason you are not getting the desired result.
So, how can you do it? Well, you need to write a stored procedure on your remote server which will return the last identity to your calling local server.
I hope you understand
Jignesh TrivediPosted May 24, 2012, 8:47 AM
@@IDENTITY or SCOPE_IDENTITY() is give perfect result.
Can you please share your code to identify problem?
thx.
Vikrant MorePosted May 24, 2012, 6:38 AM
In this case why don't you try to get the max id of your identity column which is the simplest way to get the last inserted identity.
say suppose you have column name id as an identity(1,1) and if you want to get the last inserted record then get the max(id) asign it to some variable and run the select query with where clause id = max(id)
say suppose i have above table Login and i have SrNo as int identity(1,1)
so my query to fetch the last inserted record will be as follow,
declare @max_id int
select @max_id=MAX(Srno) from login
select * from login where Srno=@max_id
Out Put :-
Thanks!
brunda kPosted May 24, 2012, 6:29 AM