OFFSET与SQL Server 2008R2不起作用

时间:2015-02-20 17:22:35

标签: sql sql-server sql-server-2008-r2

我的表中有大约24000000个修订,但是当我尝试获得1到100行时,查询会占用大量时间。

我尝试使用OFFSET,因为它在SQL Server 2008 R2上与SQL Server 2012不同。

我的SQL查询如下所示:

SELECT 
    CAST(rev_date AS varchar) Rev_Date, 
    CAST(username AS varchar) UserName,
    CAST(rev AS varchar) Rev,  
    CAST(rev_type AS varchar) Rev_Type,
    CAST(id_cl AS varchar) id, 
    CAST(id_ AS varchar) abstract,
    CAST(id AS varchar) participant, 
    CAST(id_ref_decl_channel AS varchar) refDecChannel,
    CAST(old_sherpa_number AS varchar) oldSherpaNumber, 
    CAST(is_notifier AS varchar) notify, 
    CAST(is_declarer AS varchar) declarer, 
    CAST(dispatch_rate AS varchar) dispatchRate 
FROM
    (SELECT 
         CAST(inf.rev_date AS varchar) Rev_Date, 
         CAST(inf.username AS varchar) UserName,
         CAST(aud.rev AS varchar) Rev,  
         CAST(aud.rev_type AS varchar) Rev_Type,
         CAST(aud.id_cl AS varchar) id, 
         CAST(aud.id_ AS varchar) abstract,
         CAST(aud.id AS varchar) participant, 
         CAST(aud.id_ref_decl_channel AS varchar) refDecChannel,
         CAST(aud.old_sherpa_number AS varchar) oldSherpaNumber, 
         CAST(aud.is_notifier AS varchar) notify,
         CAST(aud.is_declarer AS varchar) declarer, 
         CAST(aud.dispatch_rate AS varchar) dispatchRate,
         ROW_NUMBER() OVER (ORDER BY SalesOrderDetailID) AS RowNum
     FROM 
         oth_aud aud, ref.rev_info inf 
     WHERE 
         aud.rev = inf.id_rev_info AND aud.rev_type = 0) AS SOD
WHERE 
    SOD.RowNum BETWEEN 1 AND 100

我想通过使用这种偏移原理,在我的网页中使用分页。

我知道有很多解决方案,比如jQuery的datatable,但我想要使用SQL Server。

有任何建议吗?

1 个答案:

答案 0 :(得分:2)

OFFSET存在于SQL Server 2012中