我试图做一个如此简单的任务,但它让我疯狂如何不断失败。
DECLARE @neighbour HierarchyId = (SELECT [stPath] as tmpPath
FROM [DEV].[tmp].[StrategyTable] t
WHERE ParentCode = 'TOP')
ORDER BY t.stKey DESC;
我不断收到错误
Msg 156, Level 15, State 1, Line 4
Incorrect syntax near the keyword 'ORDER'.
同时,它适用于没有where子句的东西;像
DECLARE @parent HierarchyId = (SELECT
[stPath] AS tmpPath
FROM [DEV].[tmp].[StrategyTable] t WHERE [ParentCode] = 'TOP')
WTF .......
答案 0 :(得分:1)
DECLARE @neighbour HierarchyId = (SELECT TOP 1 [stPath] as tmpPath
FROM [DEV].[tmp].[StrategyTable] t
WHERE ParentCode = 'TOP'
ORDER BY t.stKey DESC);
这应该可以达到你想要的效果。