Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Looping through multiple tables in union query

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-03-13 : 08:49:38
Samir writes "I checked you articles for
multiple tables,
multiple tables union,
string tables union,
string multiple tables union

and found no answer, so here goes...

How can I write a union query loop that unions 10 tables (same fields) without having to write 9 UNION SELECT statements. Essentially I don't want to hard code. Use as simple SQL as possible without using T-SQL specialities."

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-03-13 : 08:57:14
Why don't you want to hard code it? Are you choosing 10 tables at random? You want "as simple SQL as possible" but "I don't want to hard code". These 2 statements contradict each other.

Can you tell us more about what you're trying to do?

Edited by - robvolk on 03/13/2002 08:57:36
Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2002-03-13 : 13:23:56
why not use some form of Dynamic SQL with the table names passed in using variables?

Go to Top of Page
   

- Advertisement -