I would like to know how I can do to join the results of several selects
in the same temporary table if possible, or if there is another way to do it.
This is the code that I have at the moment:
Declare @mod as int;
Declare modelos cursor for select mod_Id from dbo.MODELS;
Open modelos;
fetch next from modelos into @mod;
while @@FETCH_STATUS = 0
BEGIN
select b.brn_Name,count(@mod) from dbo.BRANCHES b, dbo.BrnHasMac bm, dbo.MACHINES m where b.brn_Id = bm.brn_Id and m.mac_Id = bm.mac_Id and m.mod_Id = @mod group by (b.brn_Name);
FETCH NEXT FROM modelos into @mod;
END
Close modelos;
DeAllocate modelos
I am currently getting the results as follows:
+-----------+
Branch1 30
Branch2 40
+-----------+
Branch1 10
Branch2 5
+-----------+
But I would like to get them together as follows:
+-------------+
Branch1 30 10
Branch2 40 5
+-------------+