CREATE PROCEDURE SortModules
@flag int
AS
BEGIN
CASE @flag
WHEN 0 THEN SELECT FriendlyName,ModuleID FROM [dbo].[Modules] order by FriendlyName asc
WHEN 1 THEN SELECT FriendlyName,ModuleID FROM [dbo].[Modules] order by FriendlyName desc
END
END<
在上述程序中我收到了错误
。Incorrect syntax near the keyword 'CASE'.
Incorrect syntax near the keyword 'WHEN'.
Incorrect syntax near the keyword 'END'.
。
Plz帮我找错了.Thanks
答案 0 :(得分:1)
我建议你在这里使用IF
语句而不是CASE
语句。
IF @flag = 0
BEGIN
SELECT FriendlyName,ModuleID FROM [dbo].[Modules] order by FriendlyName
END
ELSE
BEGIN
SELECT FriendlyName,ModuleID FROM [dbo].[Modules] order by FriendlyName DESC
END
有关CASE
的更多信息。
答案 1 :(得分:0)
SELECT FriendlyName,ModuleID
FROM [dbo].[Modules]
ORDER BY
CASE WHEN @flag = 0 THEN FriendlyName END ASC,
CASE WHEN @flag = 1 THEN FriendlyName END DESC