Sql 子查询不是与exists存储过程一起引入的
我制作了一个存储过程,得到了下面的错误消息,不知道为什么。我一直在四处寻找答案,办公室里还有其他人,但他们都不确定这个问题。希望这里有人也有同样的问题,知道解决办法Sql 子查询不是与exists存储过程一起引入的,sql,sql-server,sql-server-2008,Sql,Sql Server,Sql Server 2008,我制作了一个存储过程,得到了下面的错误消息,不知道为什么。我一直在四处寻找答案,办公室里还有其他人,但他们都不确定这个问题。希望这里有人也有同样的问题,知道解决办法 Msg 116, Level 16, State 1, Procedure Name_Stored_Procedure, Line 113 Only one expression can be specified in the select list when the subquery is not introduced wit
Msg 116, Level 16, State 1, Procedure Name_Stored_Procedure,
Line 113 Only one expression can be specified in the select list
when the subquery is not introduced with EXISTS.
这是我的密码
Set @SQLstring =
'Update #TempTable set Col1' + case when len(Convert(Varchar, (4+@counter)))=1
then '0' else '' end
+ Convert(Varchar,(4+@counter)) + '=''' +
(select @Year, @Month,
Convert(Varchar,count(distinct Table.Column1))
from Databse.Table
where DATEPART(yy,Time) = @Year
and DATEPART(mm,Time) = @Month
and Table.Column2 = @Column2 and Column3 in ('X','Z','Y - A'))
+''' where row = ' + CONVERT(varchar,10+@somevariable * 12)
exec('' + @SQLstring +'')
如果要构建一个SQL字符串并使用动态SQL执行它,那么需要将其视为一个字符串
Set @SQLstring =
'Update #TempTable set Col'
+ case when len(Convert(Varchar, (4+@counter)))=1 then '0' else '' end
...
在内部选择中,从结果中删除@year、@month
+ ( select Convert(Varchar,count(distinct Table.Column1)) from databse.Table....
在单独的select查询中,在下面的部分中选择年、月、计数
(select @Year, @Month,
Convert(Varchar,count(distinct Table.Column1))
from Databse.Table
where DATEPART(yy,Time) = @Year
and DATEPART(mm,Time) = @Month
and Table.Column2 = @Column2 and Column3 in ('X','Z','Y - A'))
选择CONCAT(@year、@month、convert…)谢谢,很抱歉它被视为字符串。我只是忘了在描述中键入它。但还是有同样的问题。干杯