最后尝试以下方法:
exec (@query)
如果没有括号,SQL Server会将变量的值假定为存储过程名称。
或者
EXECUTE sp_executesql @query
而且这不应该是因为FULL JOIN。
但我希望您已经创建了临时表:#TrafficFinal,#TrafficFinal2,#TrafficFinal3。
请注意,在使用EXEC和sp_executesql之间有性能方面的考虑。因为sp_executesql像sp一样使用强制语句缓存。
更多细节在这里。
On another note, is there a reason why you are using dynamic sql for this
case, when you can use the query as is, considering you are not doing any
query manipulations and executing it the way it is?



