I am using OPENQUERY to do an insert from MSSQL 2005 to MySQL. How do I get at the last inserted id on the MySQL db back into my MSSQL procedure?
Asked
Active
Viewed 1,365 times
1 Answers
0
By the following work around i can able to solve my problem Following function to get identity value
CREATE FUNCTION GetIdentity ( @tablename varchar(50) )
RETURNS varchar(50)
AS
BEGIN
-- Return the result of the function
RETURN (select cast(IDENT_CURRENT(@tablename) as varchar(50)))
END
GO
SELECT id FROM OPENQUERY(IMDECONP38, 'select Customer.dbo.GetIdentity (''CustomerMaster'') as id')
related question : SQL Server identity issue

Community
- 1
- 1

Pranay Rana
- 175,020
- 35
- 237
- 263
-
The first openqury would do the insert, and would another second openquery command call this function? And if so, would the scope still be ok? – Aditya T May 13 '10 at 17:45
-
no its out of scope because its querying data from remote server. Thats y i created this function in remote server database to get identity value – Pranay Rana May 13 '10 at 18:01