Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

insert dynamically and return @identity value

$
0
0

Dear All,
this is my coding which inserts some value into User_log table and returns @identity value .
please help me.
thanks in adv.

Declare @NewDB varchar(max);
SET @NewDB='ta.dbo.user_log ( CLIENT_ID,USER_ID,USER_NAME,LOGIN_TIME)'
DECLARE @sqlQueryUserLogId nvarchar(MAX),@UserLogId bigint
DECLARE @ParmDefinitionUserLogId nvarchar(500);
SET @sqlQueryUserLogId='insert into  '+ @NewDB+'  values( User_Name=''' + @User_Name + ''' ,User_ID=''' + @User_Id + ''' , Client_Id='''+cast(@Client_Id as varchar(20))+''',LOGIN_TIME=GetDate() )';
SET @ParmDefinitionUserLogId= N'@UserLogId bigint OUTPUT'
EXEC sp_executesql @sqlQueryUserLogId,@ParmDefinitionUserLogId, @UserLogId=@@IDENTITY OUTPUT
SET @UserLogId=@@

Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>