我有以下查询,它总是给出错误。有人可以帮我解决这个问题吗?
“关键字'@stqsql'附近的语法不正确”。
我的代码是:
declare @strsql nvarchar(max)
set @strsql=select merchantid from employee
select *
from
(
Select s.employeeid,
COUNT(*) as TotCount
from Employee s
GROUP BY s.employeeid
)as a
pivot (avg(TotCount) for employeeid IN ('+@stqsql+')) AS NoOfRec