Re: help neeed statement

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: J O Holloway (respond.to.group_at_your.convenience)
Date: 06/17/04


Date: Thu, 17 Jun 2004 15:27:02 -0500

One way to do it, and I'm not saying this is the best, is to use something
like this:

select 'select * from ' + name
from sysobjects
where type = 'U'
  and name like 'Mail%'

Set that up as a cursor in a stored procedure, and run through it building
your statement until you end up with:
select *
from Mail1
union all
select *
from Mail2
union all
select *
from Mail3

You've been storing that in a variable, such as @SQL, and now you can run
execute(@SQL).

"Darren Spooner" <DarrenS@ihatespam.spacecamp.com> wrote in message
news:OgJCoVKVEHA.2544@TK2MSFTNGP10.phx.gbl...
> i need to create a union select statement with all tables that have 'Mail'
> in the name of the table.
> i will have an unknow number of tables (Mail, Mail1, Mail2, Mail3, .....)
> how would i creat the statement?
>
>



Relevant Pages

  • Re: Christianity - a dirty word?
    ... My union colluded with the management to bring us a new ... the new contract vocally, the union did not like that, lucky I did not ... You've seen my picture. ... Next, you'll be saying things like "I know what you drive and the kind of house you live in", as if it means anything. ...
    (rec.boats)
  • Re: Christianity - a dirty word?
    ... My union colluded with the management to bring us a new ... the new contract vocally, the union did not like that, lucky I did not ... You've seen my picture. ... Next, you'll be saying things like "I know what you drive and the kind of house you live in", as if it means anything. ...
    (rec.boats)
  • Re: Christianity - a dirty word?
    ... My union colluded with the management to bring us a new ... the new contract vocally, the union did not like that, lucky I did not ... You've seen my picture. ... you'll be saying things like "I ...
    (rec.boats)
  • Re: Christianity - a dirty word?
    ... My union colluded with the management to bring us a new ... the new contract vocally, the union did not like that, lucky I did not ... You've seen my picture. ... Next, you'll be saying things like "I know what you drive and the kind of house you live in", as if it means anything. ...
    (rec.boats)
  • Re: help neeed statement
    ... > from sysobjects ... >> i need to create a union select statement with all tables that have ... >> how would i creat the statement? ...
    (microsoft.public.sqlserver.programming)