Thanks guys for the exmples and hints
[quoted text, click to view] "Ishan Bhalla" wrote:
> Union operator
>
> I want to use a union operator across sp’s!!!
>
> Take the following example:
>
> I can say
>
> select * from authors
> where au_lname ='White'
>
> Union
>
> Select * from authors
> where au_lname= 'Green'
>
>
> Lets say I call the 1st SQL Statement sp1, and the 2nd one sp2.
>
> So logically I should be able to say:
>
> Sp1
>
> Union
>
> Sp2
>
> And get the same results. The problem is I get a syntax error!!
> There are lots selective union operations
> I want to achieve code reusability
>
union all clause works only with SELECT statements. if possible try to merge
select statements in one stored procedure.
you can try following workaround as well.
ex:
--merging two row sets from sp_who stored procedure by temporarily sending
output to temp tables.
use master
go
EXEC sp_serveroption '<server_name>', 'data access' , 'true'
go
select * into #t
from openquery (<server_name>, 'exec sp_who')
go
select * into #t1
from openquery (<server_name>, 'exec sp_who')
go
select * from #t
union all
select * from #t1
--
Vishal Parkar
vgparkar@yahoo.co.in | vgparkar@hotmail.com