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 Erland Sommarskog on 03/29/07 12:10

bubbles (bubbles.one@hotmail.com) writes:
> 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.

First lesson in SQL: stop think in loops. The normal approach is that you
handle all data at once as in the query that I showed you. There are
exceptions when looping may be called for, or may be the best solution,
but nothing you have said this far, indicates that this would be necessary.

Since I don't know what the queries against TableB look like, I cannot
assist more than with the example I provided. I forgot to mention that
it runs in the Northwind database. (Which does not ship with SQL 2005,
but is on SQL 2000, and can be downloaded from Microsoft.com.)




--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

 

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

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