Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Combine 3 select statement into one table

Author  Topic 

kdeutsch
Yak Posting Veteran

83 Posts

Posted - 2009-11-01 : 16:43:11
Right now the below select statements are 3 seperate pulls from the db into 3 seperate datagrids on a page. What the users want is one datagrid that shows all of them with the totals and then an overall total at the bottom. so currently this is info from my datagrid witht he titles above. This is the results of the 3 current sql pulls, as you can see they vary in amount of data they can pull, and this is one reason I did 3 different ones. Is there a way I can combine all my sql statements into 1 and then I can pull it onto a datagrid in asp.net

POfficer WOfficer WEnlist
MOS QTY MOS QTY MOS QTY
01A00 1 251A 11B1O 4
02A00 1 11B2O 2
02B00 1 11B3O 2
13Z5O 1


kdeutsch
Yak Posting Veteran

83 Posts

Posted - 2009-11-01 : 16:45:52
Sorry forgot to post the sql
Select p.strMoS as MOS,
Count(p.strMOS) as QTY
from tblUnitPosition as p
where p.intAsgnstr = 0 AND
p.intUnitMobId = 458 AND
substring(p.strGrade, 1,1) = 'O'
Group by strMos

Select p.strMoS as MOS,
Count(p.strMOS) as QTY
from tblUnitPosition as p
where p.intAsgnstr = 0 and
p.intUnitMobId = 458 and
substring(p.strGrade, 1,1) = 'W'
Group by strMos

Select p.strMoS as MOS,
Count(p.strMOS) as QTY
from tblUnitPosition as p
where p.intAsgnstr = 0 and
p.intUnitMobId = 458 and
substring(p.strGrade, 1,1) = 'E'
Group by strMos
Go to Top of Page
   

- Advertisement -