我无法订购从事务返回的结果集。
我收到错误:
关键字' ORDER'附近的语法不正确。
我的代码:
IF EXISTS (SELECT MenuItemID
FROM dbo.Menu_Items_Custom
WHERE PodID = 288 )
BEGIN
(SELECT
C.MenuItemID,
ISNULL(NewName, ItemName) AS ItemName,
ISNULL(URL, ItemURL) AS ItemURL,
M.Type,
C.OrderBy
FROM
Menu_Items_Custom C
LEFT JOIN
Menu_Items M ON M.MenuItemID = C.MenuItemID
WHERE
(ChildOf IS NULL AND PodID = 288)
ORDER BY
C.OrderBy);
END;
ELSE
BEGIN
(SELECT *
FROM dbo.Menu_Items
WHERE ChildOf IS NULL);
END;
答案 0 :(得分:2)
无需将SELECT
括在括号中,也可以删除2个额外的分号:
IF EXISTS ( SELECT MenuItemID
FROM dbo.Menu_Items_Custom
WHERE PodID = 288 )
BEGIN
SELECT C.MenuItemID ,
ISNULL(NewName, ItemName) AS ItemName ,
ISNULL(URL, ItemURL) AS ItemURL ,
M.Type ,
C.OrderBy
FROM Menu_Items_Custom C
LEFT JOIN Menu_Items M ON M.MenuItemID = C.MenuItemID
WHERE (ChildOf IS NULL
AND PodID = 288)
ORDER BY C.OrderBy
END
ELSE
BEGIN
SELECT *
FROM dbo.Menu_Items
WHERE ChildOf IS NULL
END;