You are here: Re: Run query based on values in another table « MsSQL Server « IT news, forums, messages
Re: Run query based on values in another table

Posted by bubbles on 03/29/07 08:53

Thanks for the reply.

What I need to do is this:

Every night I pull data from a likned server. This is an automated
job.

>From this data pull, I'll generate a list of products into a table
(TableA).

TableB contains millions of records with the details of transactions
on the products.

I want to loop through TableA's values (product names) to generate and
run a series of
SQL statements with these value so I can generate various analyses.

Thanks,
Bubbles



On Mar 29, 3:22 pm, Erland Sommarskog <esq...@sommarskog.se> wrote:
>
> It is not unlikely that this is a single SQL statement, but it depends on
> what operation you intend do to on TableB. Assuming that the operation
> is "Give me the total order sum for each customer", the query in Northwind
> is:
>
> SELECT C.CompanyName, SUM(OD.Quantity * OD.UnitPrice)
> FROM [Order Details] OD
> JOIN Orders O ON OD.OrderID = O.OrderID
> JOIN Customers C ON O.CustomerID = C.CustomerID
> GROUP BY C.CompanyName
>
> A very important lesson of this is that the mindset in SQL is completely
> different from a client language.
>
> --
> Erland Sommarskog, SQL Server MVP, esq...@sommarskog.se
>
> Books Online for SQL Server 2005 athttp://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books...
> Books Online for SQL Server 2000 athttp://www.microsoft.com/sql/prodinfo/previousversions/books.mspx- Hide quoted text -
>
> - Show quoted text -

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация