我有以下SELECT
声明,我需要添加ORDER BY [UserName]
。
SELECT *
FROM [UserInfo]
WHERE ([AWSAccountID] = CASE WHEN @AWSAccountID = -1 THEN [AWSAccountID]
ELSE @AWSAccountID END)
我在确定ORDER BY
需要去哪里时会遇到一些麻烦,假设它可以添加。
答案 0 :(得分:7)
除非我遗漏了某些内容,否则您只需将ORDER BY
添加到查询的末尾:
SELECT *
FROM [UserInfo]
WHERE ([AWSAccountID] = CASE WHEN @AWSAccountID = -1 THEN [AWSAccountID]
ELSE @AWSAccountID END)
ORDER BY [UserName]