Re: help neeed statement
From: J O Holloway (respond.to.group_at_your.convenience)
Date: 06/17/04
- Next message: kirk1880: "RE: Bulk insert"
- Previous message: kirk1880: "RE: inserting result set into table"
- In reply to: Darren Spooner: "help neeed statement"
- Next in thread: kirk1880: "RE: help neeed statement"
- Messages sorted by: [ date ] [ thread ]
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?
>
>
- Next message: kirk1880: "RE: Bulk insert"
- Previous message: kirk1880: "RE: inserting result set into table"
- In reply to: Darren Spooner: "help neeed statement"
- Next in thread: kirk1880: "RE: help neeed statement"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|