2016-08-08 15 views
-1

Ich habe lange SQL-Abfrage, die etwa 35 Sekunden dauert, um die Daten auszuführen. Also möchte ich die Daten auf 10 Datensätze mit jeweils Offset und Limit wie mysql auf die unten stehende mssql-Abfrage beschränken?Wie LIMIT mit der folgenden Microsoft-Server-Abfrage zu implementieren

SELECT  distinct PAsGroupBuyData.groupPA, PAsGroupBuyData.dateShipOn, PAsGroupBuyData.dateShipOn2, PAsGroupBuyData.packingSlipsMade, PAsGroupBuyData.productionTime, PAsGroupBuyData.reorder, DSD.designName, DSD.designCode, DSD.designId, 
        DSD.dsId, PAsGroupBuyData.machineId, orderType = 1 
         FROM   Quotes_Manufacturer INNER JOIN 
               PAsData ON PAsData.PA = Quotes_Manufacturer.PA INNER JOIN 
               PAsGroupBuyData ON PAsGroupBuyData.groupPA = PAsData.GroupPa INNER JOIN 
               DesignSystemDesigns DSD ON PAsGroupBuyData.designId = DSD.designId 
         WHERE (PAsGroupBuyData.status = 3) AND (Quotes_Manufacturer.accepted = 1) and (PAsGroupBuyData.dateShipOn <> '".$thisSunday."') and (PAsGroupBuyData.dateShipOn <> '".$lastSunday."') 
         UNION ALL 
         SELECT distinct PAsGroupBuyData.groupPA, PAsGroupBuyData.dateShipOn, PAsGroupBuyData.dateShipOn2, PAsGroupBuyData.packingSlipsMade, PAsGroupBuyData.productionTime, PAsGroupBuyData.reorder, DSD.designName, DSD.designCode, DSD.designId, 
               DSD.dsId, PAsGroupBuyData.machineId, orderType = 2 
         FROM   Quotes_SupplierAndManufacturerGroupBuy INNER JOIN 
               PAsGroupBuyData ON PAsGroupBuyData.groupPA = Quotes_SupplierAndManufacturerGroupBuy.groupPA INNER JOIN 
               DesignSystemDesigns DSD ON PAsGroupBuyData.designId = DSD.designId INNER JOIN 
               PAsData ON PAsData.GroupPa = PAsGroupBuyData.groupPA 
         WHERE  (PAsGroupBuyData.status = 3) AND (Quotes_SupplierAndManufacturerGroupBuy.accepted = 1) and (PAsGroupBuyData.dateShipOn <> '".$thisSunday."') and (PAsGroupBuyData.dateShipOn <> '".$lastSunday."') 
         UNION ALL 
         SELECT  PAsData.PA, PAsData.dateShipOn, PAsData.dateShipOn2, PAsData.packingSlipsMade, PAsData.productionTime, PAsData.reorder, DSD.designName, DSD.designCode, DSD.designId, DSD.dsId, 
               PAsData.machineId, orderType = 3 
         FROM   Quotes_Manufacturer INNER JOIN 
               PAsData ON PAsData.PA = Quotes_Manufacturer.PA INNER JOIN 
               DesignSystemDesigns DSD ON PAsData.designId = DSD.designId 
         WHERE  (Quotes_Manufacturer.accepted = 1) AND (PAsData.status = 3) AND (PAsData.GroupPa = 0) and (PAsData.dateShipOn <> '".$thisSunday."') and (PAsData.dateShipOn <> '".$lastSunday."') 
         UNION ALL 
         SELECT  PAsData.PA, PAsData.dateShipOn, PAsData.dateShipOn2, PAsData.packingSlipsMade, PAsData.productionTime, PAsData.reorder, DSD.designName, DSD.designCode, DSD.designId, DSD.dsId, 
               PAsData.machineId, orderType = 4 
         FROM   Quotes_SupplierAndManufacturer INNER JOIN 
               PAsData ON PAsData.PA = Quotes_SupplierAndManufacturer.PA INNER JOIN 
               DesignSystemDesigns DSD ON PAsData.designId = DSD.designId 
         WHERE  (PAsData.status = 3) AND (Quotes_SupplierAndManufacturer.accepted = 1) AND (Pasdata.groupPa = 0) and (PAsData.dateShipOn <> '".$thisSunday."') and (PAsData.dateShipOn <> '".$lastSunday."') 
         UNION ALL 
         SELECT  ID As PA, _Date As dateShipOn, _Date As dateShipOn2, 0 As packingSlipsMade, productionTime, 0 As reorder, Title As designName, ' ' As designCode, 0 As designId, 0 As dsId, 
               machineId, orderType = 5 
         FROM   Calendar 
         WHERE  (_Date <> '".$thisSunday."') and (_Date <> '".$lastSunday."') and (_Date > getDate()-1) and (_Date < (getDate()+30)) 
         ORDER BY PAsGroupBuyData.dateShipOn, PAsGroupBuyData.machineId, PAsGroupBuyData.groupPA 
+1

Google: "holen Zeilen nur Offset". –

+0

Danke für die Hilfe :) –

Antwort

0

Dank an Gordon. Ich habe die korrekte Syntax gefunden, um Offset und Limit mit Mssql-Abfragen zu verwenden.

Example: offset ".$offset." ROWS FETCH NEXT ".$limit." ROWS ONLY