SELECT * FROM (SELECT ROW_NUMBER() OVER (ORDER BY hrl.Frn) as Row,
hrl.unq, hrl.LcnsId, hc.Business,hc.Name,hc.Phone,
hrl.Frn,hrl.CallSign, hrl.gsamarkettypeid,
gmt.[Market Type Code] + ' - ' + gmt.gsamarkettype,
hrl.gsalatitude,hrl.gsalongitude,
rsc.RadioServiceCode + ' - ' + rsc.RadioService,
GrantDt, ExpirationDt, EffectiveDt,
CancellationDt
FROM dbo.sbi_f_HldrRgstrtnLcns hrl
INNER JOIN dbo.sbi_f_HldrCntcts hc on
hc.CallSign = hrl.CallSign
INNER JOIN dbo.sbi_l_radioservicecodes rsc on
rsc.radioservicecodeid = hrl.radioservicecodeid
LEFT OUTER JOIN dbo.sbi_l_GSAMarketTypes gmt on
gmt.GSAMarketTypeId = hrl.GSAMarketTypeId
WHERE hc.Entity_Type = 'L' AND hrl.LicenseStatusId IN (1)
and Row >=1 and Row <= 20) -- The error occurs here,
-- it says incorrect syntax near )
Xaisoft
问问题
811 次
4 回答
6
将您的行条件移动到外部选择中
SELECT * FROM (SELECT ROW_NUMBER() OVER (ORDER BY hrl.Frn) as Row,
...
WHERE hc.Entity_Type = 'L' AND hrl.LicenseStatusId IN (1)
) T
WHERE T.Row >=1 and T.Row <= 20)
于 2008-12-10T21:06:36.463 回答
1
您可以使用 CTE 执行此操作:
WITH NumberedRows AS
(
SELECT
ROW_NUMBER() OVER (ORDER BY hrn.Frl) AS RowNum,
...
WHERE
hc.Entity_Type = 'L'
AND hrl.LicenseStatusId IN (1)
)
SELECT
*
FROM
NumberedRows
WHERE
RowNum <= 20
于 2008-12-10T21:11:01.977 回答
0
您不能在 where 子句中为列使用别名,因为 where 子句在 Select 子句之前处理。
编辑:
您也可以在 where 子句中添加子查询
Where ((SELECT ROW_NUMBER() OVER (ORDER BY hrl.Frn)) < 20,
或根本不使用 Row_Number,
Where (Select Count(*)
From dbo.sbi_f_HldrRgstrtnLcns
Where Frn < hrl.Frn) < 20
于 2008-12-10T21:03:10.387 回答
0
检查您使用的是哪个版本的 sql server 数据库。row_number 从 sql server 2005 开始添加。它不支持 sql server 2000
于 2008-12-29T15:22:46.817 回答