クエリ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)
クエリ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では、関数fnSplitに渡す変数deに置き換えています。ここで、値をコンマで区切って分割します。エラーメッセージが表示されますMust declare the scalar variable "@OfferID"
。ここで問題がどこにあるか教えてください。