当我尝试运行以下查询时
DECLARE @QUERY1 VARCHAR(MAX)
SET @QUERY1=(SELECT [ResponsibleEngineerID],[ResponsibleEngineer],DocType
FROM tblResponsibleEngineer
WHERE ResponsibleEngineer NOT IN ('(Select a Responsible Engineer...)')
ORDER BY [ResponsibleEngineer] ASC
)
EXEC(@QUERY1)
我得到了错误
ORDER BY 子句在视图、内联函数、派生表、子查询和公用表表达式中无效,除非还指定了 TOP 或 FOR XML。
为什么会出现这个错误?我需要完全按照上述格式编写sql查询。比如将查询分配给一个变量,然后执行