Question : How to create a SQL loop to create a dataset

Hello

I have a table of suppliers:

SupplierID | Supplier
----------------------
7          | SuppA
9          | SuppB
13         | SuppC

..etc.

And I am using this query to retrieve some information from a table called Webstat, which is related to Supplier:

SELECT     AVG(Transfer) AS Average
FROM         Webstat
WHERE     (DateCreated >= DATEADD([month], - 3, GETDATE())) AND (SupplierID = 27)

Now in web code (c#) I have a loop. I get all the Suppliers, and I call the above query, but substituting the SupplierID.

Now is it possible to write query, whereby I can have a dataset returned that has all the suppliers from the Supplier table as well as the Averages calculated using the above query.. and ordered by Average.

Any ideas/help would be greatly appreciated.

Answer : How to create a SQL loop to create a dataset

SELECT     W.SupplierID ,AVG(Transfer) AS Average
FROM         Webstat W
inner join  suppliers  S
On S.SupplierID  = W.SupplierID
WHERE     (DateCreated >= DATEADD([month], - 3, GETDATE()))
group by W.SupplierID
Random Solutions  
 
programming4us programming4us