TSQL: the union is obtained from two samples (procedures?)

I have two procedures - two huge sets of samples with several sub-samples and joins. I need to combine the results of these procedures, and I still need them to exist separately.

Something like that:

if @Param = 1 Then 
    PROCEDURE1
if @Param = 2 THEN 
    PROCEDURE2
if @Param = 3 Then
    PROCEDURE1 union PROCEDURE2

I read that it is not possible to combine procedures, and I cannot use temporary tables.

Any idea?

+5
source share
4 answers

You can convert procedures to views.

OR

You can execute the procedures in the temp table, and then execute another in the same temp table:

create table #sometable (table definition here)

if @Param = 1 or @Param = 3 begin
    insert #sometable exec PROCEDURE1
end

if @Param = 2 or @Param = 3 begin
    insert #sometable exec PROCEDURE2
end

select * from #sometable
+7
source

You can:

1) temp, SELECT:

--Define #t here, with correct schema to match results returned by each sproc
INSERT #t EXECUTE PROC1
INSERT #t EXECUTE PROC2
SELECT * FROM #t

2) 2 sproc 2

+3

:

, , . , .

+2

, .

  • s'procs , .

  • , proc ( ). .

+1

All Articles