DECLARE @MaxID bigint DECLARE @temp nVARCHAR(4000) select @temp='SELECT @MaxID = max(id) from(SELECT TOP 200 id FROM (select * from testtable) as T9 ORDER BY id) as T2' EXEC (@temp) exec sp_executesql @temp,N'@MaxID bigint output',@MaxID output
sorry,多了一句: DECLARE @MaxID bigint DECLARE @temp nVARCHAR(4000) select @temp='SELECT @MaxID = max(id) from(SELECT TOP 200 id FROM (select * from testtable) as T9 ORDER BY id) as T2' exec sp_executesql @temp,N'@MaxID bigint output',@MaxID output
要这么麻烦吗?DECLARE @MaxID bigint SELECT @MaxID = max(id) from (SELECT TOP 200 id FROM testtable ORDER BY id ) as T2
DECLARE @temp nVARCHAR(4000)
select @temp='SELECT @MaxID = max(id) from(SELECT TOP 200 id FROM (select * from testtable) as T9 ORDER BY id) as T2'
EXEC (@temp)
exec sp_executesql @temp,N'@MaxID bigint output',@MaxID output
DECLARE @MaxID bigint
DECLARE @temp nVARCHAR(4000)
select @temp='SELECT @MaxID = max(id) from(SELECT TOP 200 id FROM (select * from testtable) as T9 ORDER BY id) as T2'
exec sp_executesql @temp,N'@MaxID bigint output',@MaxID output
SELECT @MaxID = max(id)
from (SELECT TOP 200 id FROM testtable ORDER BY id
) as T2