查询一:
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)
查询 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)
查询 1 工作正常。在 query2 中,我将替换为 de 定义的变量,在该变量中我传递给函数 fnSplit,在该函数中我用逗号分隔值。我收到一条错误消息Must declare the scalar variable "@OfferID"
。请让我知道这里的问题在哪里。