Query 1:
SET @sql2 = 'insert into TempReport
select ID, max(TransactionTime),0 from ClubTransaction with (nolock)
where ClubcardID in (select ClubcardID from TempCC)
and ClubcardTransaction.OfferID not in (119,120,121)
group by ClubcardID'
exec (@Sql2)
Query 2:
delcare @OfferID varchar(50)
set OfferID='1,112,445,'
SET @sql2 = 'insert into TempReport
select ID, max(TransactionTime),0 from ClubTransaction with (nolock)
where ClubcardID in (select ClubcardID from TempCC)
and ClubcardTransaction.OfferID not in (Select Item From dbo.fnSplit(@OfferID,'','')
group by ClubcardID'
exec (@Sql2)
Query 1 works fine. In query2 I am replacing with an variable de defined where I am passing to the function fnSplit where I split the values with comma separated.
I get an error message Must declare the scalar variable "@OfferID".
Please let me know where is the issue here.