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.
Author |
Topic |
planetoneautomation
Posting Yak Master
105 Posts |
Posted - 2014-10-09 : 16:16:30
|
Here's the query:SELECTTC_STATUS AS 'Status', COUNT(*) as 'Total'FROMTESTCYCLJOIN TEST ON TS_TEST_ID = TC_TEST_IDJOIN RELEASE_CYCLES ON TC_ASSIGN_RCYC = RCYC_IDWHERE RCYC_NAME = '(PQ) Test Cycle 3' AND TEST.TS_NAME Like '3.%'GROUP BY TC_STATUSORDER BY TC_STATUS Here's the question:This query might return up to 5 different values for TC_STATUS. But it might return no rows or rows for one value or two values or three values or four values.For example, what returns might have all possible status values:STATUS .............TOTALNot Covered ....... 8No Run .............10Not Completed ......23Passed .............118Failed .............25Or, maybe what's returned contains only four of the five possible:STATUS .............TOTALNot Covered ....... 8No Run .............10Passed .............118Failed .............25Or, even none of the possible values.What I want is, a row returned for every status regardless of whether it has a value or not - like this:STATUS .............TOTALNot Covered ....... 0No Run .............10Not Completed ......0Passed .............118Failed .............25In the above, no rows are returned for Not Covered or for Not Completed but I want to write the status value and the count of zero regardless.Is this possible? |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
kostya1122
Starting Member
15 Posts |
Posted - 2014-10-09 : 17:55:21
|
you could try something like thiscreate table #temp(col1 varchar(30))insert into #temp values('STATUS')insert into #temp values('Not Covered')insert into #temp values('No Run')insert into #temp values('Not Completed')insert into #temp values('Passed')insert into #temp values('Failed')SELECTTC_STATUS AS 'Status', COUNT(*) as 'Total'into #temp2FROMTESTCYCLJOIN TEST ON TS_TEST_ID = TC_TEST_IDJOIN RELEASE_CYCLES ON TC_ASSIGN_RCYC = RCYC_IDWHERE RCYC_NAME = '(PQ) Test Cycle 3' AND TEST.TS_NAME Like '3.%'GROUP BY TC_STATUSORDER BY TC_STATUSselect x.col1 as [status], y.Totalfrom #temp as xleft join #temp2 as yon x.col1 = y.[Status] |
|
|
mmkrishna1919
Yak Posting Veteran
95 Posts |
Posted - 2014-10-10 : 09:13:27
|
As tkizer said try with left join and keep table which contain "TC_STATUS" column on left side of join.M.MURALI kRISHNA |
|
|
|
|
|