I have something like this.
declare @insertQuery nvarchar(max)
declare @ifQuery nvarchar(max)
SET @insertQuery='...'
SET @ifQuery='if not exists(select Id from '+@DbName+'.[dbo].[tbl_TestHere] where Id='+@id+')'
BEGIN
Exec sp_executesql @insertQuery
END
I need to execute dynamic query @insertQuery if "if not exists(...)" returns true..But i couldn't find right solution for this. Thanks in advance