开发者

T-SQL OPENQUERY to MySQL - Insert ID

开发者 https://www.devze.com 2022-12-29 21:29 出处:网络
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?By the following work around i can able

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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号