I have created a trigger and inside it, there's dynamic SQL gets executed.
Here is sample script:
When I specifying @Text
to some value,it work (after exec showing 1 row affetected)but when I am specifying null,
record not get added into table(Message:query executed sucessfully).I want like like his,if record not get added into sample table,pls add into Sample 2 without dynamic insertion.How to find out dynamic exec successfully or not.I don't want fetch last identity of table.How to do that?
declare @Inserttbl nvarchar(4000)
declare @TableName varchar(50)
declare @PId int
declare @Text varchar(50)
declare @count int
declare @Status int
set @TableName ='sample'
set @Text = null
set @PId = 3
set @Status =1
set @Inserttbl = ' Insert into Test.dbo.' +@TableName +' values ('+@PId+','+@Text+','+@Status+')'
exec sp_executesql @Inserttbl