Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Query #2 - MySQL and MS-SQL
Message
From
27/02/2008 13:56:34
 
 
To
27/02/2008 04:44:51
Walter Meester
HoogkarspelNetherlands
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
01296743
Message ID:
01297028
Views:
26
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform