December 3, 2009 at 12:33 pm
Hi All,
Can i give multiple conditons in one statement ? Actually in my SQL i have two columns comes from view F
TS_USER_18 TS_USER_11
P1
P1 NP
P1 P1
I want to count only where Provider is P1 and AltProvider is empty. I don't know why following SQL is not returning correct result. When I give only one condition i get correct value from the table.
SELECT F.Requirements
, Count(F.TS_NAME)AS TotalTestCases
, COUNT(CASE WHEN TS_USER_18 Like '%P1%' And TS_USER_11 <> '' Then TS_USER_18 END) AS P1
, COUNT(CASE WHEN TS_USER_18 Like '%P2%' Then TS_USER_18 END) AS P2
, COUNT(CASE WHEN TS_USER_18 Like '%NP%' Then TS_USER_18 END) AS NP
, COUNT(CASE WHEN TS_USER_11 <> '' Then TS_USER_11 END) AS AltProvider
From (
SELECT Distinct TEST.TS_NAME,
(
SELECT TESTCYCL.TC_STATUS from TESTCYCL where TEST.TS_TEST_ID = TESTCYCL.TC_TEST_ID and TESTCYCL.TC_CYCLE_ID =
(Select max(TESTCYCL.TC_CYCLE_ID) from TESTCYCL WHERE TESTCYCL.TC_TEST_ID = TEST.TS_TEST_ID)) AS STATUS
,TEST.TS_USER_24 AS TC_VALIDATED, Requirements =
Case
WHEN RQ_REQ_PATH Like 'AAAAADAARAADAAC%' Then 'Medi'
WHEN RQ_REQ_PATH Like 'AAAAADAALAAN%' THEN 'MHS'
WHEN RQ_REQ_PATH Like 'AAAAADAALAAPAAB%' THEN 'OB90'
Else
'Unknown'
END, TEST.TS_USER_18, TEST.TS_USER_11, TEST.TS_USER_14, TEST.TS_USER_22
FROM TEST, REQ_COVER, REQ
WHERE TEST.TS_TEST_ID = REQ_COVER.RC_ENTITY_ID AND REQ.RQ_REQ_ID = REQ_COVER.RC_REQ_ID
) F
Group by F.Requirements
December 3, 2009 at 12:40 pm
Your text says you want the second column to be blank, but the actual code tests the exact opposite, so far as I can tell. What am I missing?
And TS_USER_11 <> ''
That part of the code is testing to make sure it is NOT blank.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
December 3, 2009 at 12:45 pm
oK Let me explain. Let say my table is something like this.
TS_USER_11 TS_USER_18
P1
P1 P2
P2
P1
P1 P1
P2
P1
NP P2
P1
I need out put like this . It will show how 9 rows are distributed across different providers (P1, P2, NP and Alternate)
P1 P2 NP Alt(Where TS_USER18 is not equal to null)
4 2 0 3
December 3, 2009 at 12:58 pm
This is how I like to do that kind of thing in SQL 2000. (It's easier in SQL 2005 with the Pivot command.)
if object_id(N'tempdb..#T') is not null
drop table #T;
create table #T (
ID int identity primary key,
TS_USER_11 char(2),
TS_USER_18 char(2));
insert into #T (TS_USER_11, TS_USER_18)
select 'P1','' union all
select 'P1','P2' union all
select 'P2','' union all
select 'P1','' union all
select 'P1','P1' union all
select 'P2','' union all
select 'NP','P2' union all
select 'P1','';
select
(select count(*)
from #T
where TS_USER_11 = 'P1'
and TS_USER_18 = '') as P1,
(select count(*)
from #T
where TS_USER_11 = 'P2'
and TS_USER_18 = '') as P2,
(select count(*)
from #T
where TS_USER_11 = 'NP'
and TS_USER_18 = '') as NP,
(select count(*)
from #T
where TS_USER_18 != '') as Alt;
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy