gpt4 book ai didi

SQL Server 2008 选择由变量定义的前 100 个

转载 作者:行者123 更新时间:2023-12-04 19:30:10 28 4
gpt4 key购买 nike

在 SQL Server 2008 中,有没有办法选择 top @top 通过变量定义值,如下面的代码?

declare @top as integer;
set @top=100;

SELECT top @top
T1.id as clientInfoId
,T1.ucsId
,T1.phoneHome
... (more columns here)......
,T1.businessTitle
FROM
YELLOW_OUT_CLIENT_INFO AS T1
LEFT JOIN
YELLOW_OUT_BUSINESS T2 on T2.clientInfoId = T1.id
WHERE
T1.AgentId=5
AND
T1.deleted IS NULL
... (more conditions here)......
ORDER BY NEWID()

最佳答案

将变量放在括号中:

SELECT top (@top)

This functionality was added in SQL Server 2005 ... 2000 是您必须执行 SET ROWCOUNT @top

的最后一个版本

关于SQL Server 2008 选择由变量定义的前 100 个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9116110/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com