0

重複の可能性:
SQL Server の行オフセット

like 条件を持つクエリがあり、約 1500 行が返されます。ここで、行を部分的に取得する方法を知りたいです。たとえば、75行を返し、次に行の終わりに達するまで次の75行を返します。私は次のようなものを使用できることを知っていますSELECT TOP 75

このようなことを試しましたが、行が返されません

    SELECT * 
    FROM 
       (SELECT ROW_NUMBER() OVER (ORDER BY WarehouseSubType.id) as row,
               WarehouseSubType.id, 
               WarehouseType.name as WarehouseTypename,
               WarehouseType.alternateName AS WarehouseTypealternateName,
               WarehouseSubType.name AS WarehouseSubTypename,
               Warehouse.alternateName AS WarehousealternateName,
               WarehouseSubType.alternateName AS WarehouseSubTypealternateName,
               WarehouseSubType1.name AS WarehouseSubType1name,
               WarehouseSubType1.alternateName AS WarehouseSubType1alternateName,
               Warehouse.alternateName AS Warehousename,
               Branch.name AS Branchname,
               Branch.alternateName AS BranchalternateName,
               WarehouseProductQuantity.actualQuantity,
               WarehouseProductQuantity.reservedQuantity,
               Supplier.companyName, 
               Supplier.companyNameAlternate,
               Tafsil.description,
               Tafsil.alternateDescription,
                (WarehouseProductQuantity.actualQuantity - WarehouseProductQuantity.reservedQuantity) AS quantity 
        FROM WarehouseSubType 
        INNER JOIN WarehouseType ON (WarehouseSubType.warehouseTypeId = WarehouseType.id)
        INNER JOIN WarehouseSubType1 ON (WarehouseSubType.id = WarehouseSubType1.warehouseSubTypeId)
   ) a 
WHERE 
    warehouseTypename like '%Ve%' 
    AND row > 0 and row < 75
4

1 に答える 1

1

投稿したコードは、行を返すどころか、コンパイルすることさえできません。サブクエリは閉じられておらず、行は内部クエリで認識されません。

代わりにこれを試してください:

SELECT * FROM 
   ( SELECT ROW_NUMBER() OVER (ORDER BY WarehouseSubType.id) as row,
    WarehouseSubType.id, 
    WarehouseType.name as WarehouseTypename,
    WarehouseType.alternateName AS WarehouseTypealternateName,
    WarehouseSubType.name AS WarehouseSubTypename,
    Warehouse.alternateName AS WarehousealternateName,
    WarehouseSubType.alternateName AS WarehouseSubTypealternateName,
    WarehouseSubType1.name AS WarehouseSubType1name,
    WarehouseSubType1.alternateName AS WarehouseSubType1alternateName,
    Warehouse.alternateName AS Warehousename,
    Branch.name AS Branchname,
    Branch.alternateName AS BranchalternateName,
    WarehouseProductQuantity.actualQuantity,
    WarehouseProductQuantity.reservedQuantity,
    Supplier.companyName, 
    Supplier.companyNameAlternate,
    Tafsil.description,
    Tafsil.alternateDescription,
    (WarehouseProductQuantity.actualQuantity - WarehouseProductQuantity.reservedQuantity) AS quantity 
    FROM WarehouseSubType 
    INNER JOIN WarehouseType 
        ON ( WarehouseSubType.warehouseTypeId = WarehouseType.id)
    INNER JOIN WarehouseSubType1 
        ON (WarehouseSubType.id = WarehouseSubType1.warehouseSubTypeId)) a 
    WHERE warehouseTypename like '%Ve%' ) b
WHERE b.row > 0 and b.row< 75
于 2012-10-18T16:54:20.767 に答える