| Author |
Topic  |
|
|
mohan123
Posting Yak Master
India
203 Posts |
Posted - 11/29/2012 : 01:45:13
|
select DimConditionDefinitionId ,SUM (CASE WHEN DimConditionDefinitionId between 1 and 4 THEN totalusers ELSE 0 END) /246624.0 AS PopulationCount from pop_fact
GROUP by DimConditionDefinitionId Here i am getting solution for condition 1,2,3,4 it is fine but here i need to get if i pass condition 1 and condition 2 or else condition 3 or condition 4 in jumbling way ???
i have written case condition but it is showing result set as condition 1 and condition 2.So when i give both conditions it should count both and give total count
P.V.P.MOhan |
|
|
ahmeds08
Constraint Violating Yak Guru
India
430 Posts |
Posted - 11/29/2012 : 01:57:23
|
you can do it by using IF statement. write 3 IF statements. first one for condition 1,second for condition 2 and third for condition 1 and 2. |
 |
|
|
mohan123
Posting Yak Master
India
203 Posts |
Posted - 11/29/2012 : 02:29:55
|
No it won't works it is multiplying single condition i need to get sum total of cond 1 and cond2 else cond2 and cond3 it is not about the case statement
P.V.P.MOhan |
 |
|
|
madhivanan
Premature Yak Congratulator
India
22461 Posts |
Posted - 11/29/2012 : 02:41:42
|
Post some sample data with expected output
Madhivanan
Failing to plan is Planning to fail |
 |
|
|
mohan123
Posting Yak Master
India
203 Posts |
Posted - 11/29/2012 : 03:18:29
|
dynamically i will pass condition 1 or 2 or 3 or 4 if i pass 2 parameters at one go it should show the count of 2 conditions if i pass 3 conditions at one go it should show count of 3 cond divided by 246624.0
P.V.P.MOhan |
 |
|
|
khtan
In (Som, Ni, Yak)
Singapore
16746 Posts |
Posted - 11/29/2012 : 03:28:40
|
select DimConditionDefinitionId
,SUM (CASE WHEN DimConditionDefinitionId = @condition
THEN totalusers
ELSE 0
END) /246624.0 AS PopulationCount
from pop_fact
GROUP by DimConditionDefinitionId
KH Time is always against us
|
 |
|
|
mohan123
Posting Yak Master
India
203 Posts |
Posted - 11/29/2012 : 03:37:35
|
this for single condition it works fine but when i pass 2 con ditions at one time then how i need to write the query
P.V.P.MOhan |
 |
|
|
khtan
In (Som, Ni, Yak)
Singapore
16746 Posts |
Posted - 11/29/2012 : 03:41:58
|
quote: Originally posted by mohan123
this for single condition it works fine but when i pass 2 con ditions at one time then how i need to write the query
P.V.P.MOhan
what do you mean by that ? can you illustrate with an example ?
KH Time is always against us
|
 |
|
|
mohan123
Posting Yak Master
India
203 Posts |
Posted - 11/29/2012 : 03:55:10
|
Declare @condition int
set @condition = @condition1 and @condition2 like this now it showing result of single condition count if i pass condition 1 and 2 combining count should come
select DimConditionDefinitionId ,SUM (CASE WHEN DimConditionDefinitionId = @condition THEN totalusers ELSE 0 END) /246624.0 AS PopulationCount from pop_fact GROUP by DimConditionDefinitionId
P.V.P.MOhan |
 |
|
|
khtan
In (Som, Ni, Yak)
Singapore
16746 Posts |
|
| |
Topic  |
|