T-SQL Problem
-
Hi I have a select statement that returns (A int ,B int) and another select statement that returns (C int , D int) in a storedprocedure. I need that sp returns a resultset as (A,B,C,D); What should i do plz?
-
Hi I have a select statement that returns (A int ,B int) and another select statement that returns (C int , D int) in a storedprocedure. I need that sp returns a resultset as (A,B,C,D); What should i do plz?
if they are scalar values you are dealing with then just do this.
declare @a int, @b int, @c int, @d int select @a = 1, @b= 2 select @c = 3, @d= 4 select @a as ColA, @b as ColB, @c as ColC, @d as ColD
Else, if it is a rowset, then do what alam_pune said, but pull a join column from each of the sub selects in order to join the rowsets to avoid the cartesian productselect Select1.A, Select1.B, Select2.C, Select2.D from (select A, B, PriKeyCol from Table1) as Select1 inner join (select C, D, ForKeyCol from Table2) as Select2 on select1.PriKeyCol = select2.ForKeyCol