Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server identity issue

I have a query like below

declare @str_CustomerID int
Insert into IMDECONP38.[Customer].dbo.CustomerMaster
( CustomerName , CustomerAddress , CustomerEmail , CustomerPhone )
values ( ‘werw12e’ , ‘jkj12kj’ , ‘3212423sdf’ , ‘1212121′
)

select @str_CustomerID= scope_identity()

After execution it returns null in my parameter.

I want to get the value of identity. How can I do that?

The main issue over here is "IMDECONP38" - the server name that I used. If I remove this I can get the value of identity in my parameter.

like image 980
Pranay Rana Avatar asked Apr 12 '10 12:04

Pranay Rana


1 Answers

See this old question for a similar problem: You cannot retrieve a scoped variable like SCOPE_IDENTITY() from another server. Instead, you should use a stored procedure on the remote server to achieve this.

like image 64
Prutswonder Avatar answered Oct 10 '22 17:10

Prutswonder