1

这是我的导致错误的代码:

SELECT @maxNo = TOP 1 CONVERT(INT,(SUBSTRING(noorder,7,4))) 
FROM orders ORDER BY noorder DESC;

它返回:

消息 156,级别 15,状态 1,第 2 行
关键字“TOP”附近的语法不正确。

编辑:找到答案,我应该这样编码:

select top 1 @maxNo = CONVERT(int, (SUBSTRING(noorder, 7, 4)))

来自 noorder desc 的订单;

感谢@RedFilter

4

2 回答 2

4
select top 1 @maxNo = CONVERT(int, (SUBSTRING(noorder, 7, 4)))
from orders
order by noorder desc;
于 2012-05-30T18:08:34.177 回答
1
 declare @maxNo int
 Set @maxNo = (Select TOP 1 CONVERT(INT,(SUBSTRING(noorder,7,4))) 
 FROM [order] order by  noorder desc)
 select @maxNo
于 2012-05-30T18:13:02.347 回答