0

重複の可能性:
sqlserver の LIMIT 10..20

SQL Server 2005 で次のコードを使用しようとしました (2012 年に作成されました)。

SELECT *
FROM  (SELECT TOP (100) PERCENT ID_BADGE,
                                DATE_TRX,
                                CODE_TRX,
                                SEQ_REC
       FROM   omi.DCUTRX_ZERO
       UNION ALL
       SELECT TOP (100) PERCENT ID_BADGE,
                                DATE_TRX,
                                CODE_TRX,
                                SEQ_REC
       FROM   omi.TAHIST_ZERO) OMI
WHERE  ( ID_BADGE = '     ' + @Badge )
       AND ( DATE_TRX BETWEEN @Date AND @Date2 )
       AND ( SEQ_REC IN ( '0', '1000' ) )
       AND ( CODE_TRX IN ( '100', '101' ) ) 
    OFFSET 1 ROWS 
    FETCH NEXT 2 ROWS ONLY 

SQL Server 2005 に相当するものを誰か教えてもらえますか?

4

1 に答える 1

2
SELECT  ID_BADGE, DATE_TRX, CODE_TRX, SEQ_REC
FROM    (
        SELECT  *, ROW_NUMBER() OVER (ORDER BY DATE_TRX) rn
        FROM    (
                SELECT  ID_BADGE, DATE_TRX, CODE_TRX, SEQ_REC
                FROM    omi.DCUTRX_ZERO
                UNION ALL
                SELECT  ID_BADGE, DATE_TRX, CODE_TRX, SEQ_REC
                FROM    omi.TAHIST_ZERO
                ) q
       WHERE    ID_BADGE = '     ' + @Badge
                AND DATE_TRX BETWEEN @Date AND @Date2
                AND SEQ_REC IN ('0', '1000')
                AND CODE_TRX IN ('100', '101')
       ) q
WHERE  rn BETWEEN 2 AND 3
ORDER BY
       DATE_TRX

ORDER BY動作させるには、SQLServerに何らかのものが必要であることに注意してくださいROW_NUMBER

于 2013-01-10T19:00:00.590 に答える