Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Query #2 - MySQL and MS-SQL
Message
De
27/02/2008 13:56:34
 
 
À
27/02/2008 04:44:51
Walter Meester
HoogkarspelPays-Bas
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
01296743
Message ID:
01297028
Vues:
24
I could not let it go... Everyone has its weakness... anyways

This is something very quick that runs in the QA:


Thanks for posting. That's basically how I did it prior to SQL 2005 (using a WHILE loop to build a list of dates)

In 2005, I can use a CTE and a basic recursive query to build the date list.
(Actually, I can build a 2nd CTE to come up with the unique list of vendors with orders)

My blog is acting funny, so I'll post it here:
; WITH DateCTE (WeekEnding)  AS
     -- Anchor query to get the first date
     (SELECT @StartDate AS WeekEnding
       UNION ALL
          -- Recursive query to grab the rest of the dates
          SELECT DateAdd(day,7,WeekEnding) AS WeekEnding FROM DateCTE 
             WHERE WeekEnding < @EndDate ),

       -- 2nd CTE to grab the list of Vendors
       VendorListCTE (VendorID)   AS
         (SELECT VendorID FROM Purchasing.PurchaseOrderHeader   
             GROUP BY VendorID) 
And then I can issue a subsequent query against the Orders table, using DateCTE and VendorListCTE.

Thanks,
Kevin
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform