-1

我有以下SELECT声明,我需要添加ORDER BY [UserName].

SELECT * 
FROM [UserInfo] 
WHERE ([AWSAccountID] = CASE WHEN @AWSAccountID = -1 THEN [AWSAccountID] 
ELSE @AWSAccountID END)

ORDER BY假设可以添加它,我在确定需要去哪里时遇到了一些麻烦。

4

1 回答 1

7

除非我遗漏了一些东西,否则您只需将您添加ORDER BY到查询的末尾:

SELECT * 
FROM [UserInfo] 
WHERE ([AWSAccountID] = CASE WHEN @AWSAccountID = -1 THEN [AWSAccountID] 
                           ELSE @AWSAccountID END)
ORDER BY [UserName]
于 2013-04-10T17:35:02.043 回答