Author |
Topic |
mohan123
Constraint Violating Yak Guru
252 Posts |
Posted - 2012-11-29 : 01:45:13
|
select DimConditionDefinitionId ,SUM (CASE WHEN DimConditionDefinitionId between 1 and 4 THEN totalusersELSE 0END) /246624.0 AS PopulationCount from pop_factGROUP by DimConditionDefinitionIdHere 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
Aged Yak Warrior
737 Posts |
Posted - 2012-11-29 : 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
Constraint Violating Yak Guru
252 Posts |
Posted - 2012-11-29 : 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 statementP.V.P.MOhan |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2012-11-29 : 02:41:42
|
Post some sample data with expected outputMadhivananFailing to plan is Planning to fail |
|
|
mohan123
Constraint Violating Yak Guru
252 Posts |
Posted - 2012-11-29 : 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.0P.V.P.MOhan |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-11-29 : 03:28:40
|
select DimConditionDefinitionId ,SUM (CASE WHEN DimConditionDefinitionId = @condition THEN totalusers ELSE 0 END) /246624.0 AS PopulationCount from pop_factGROUP by DimConditionDefinitionId KH[spoiler]Time is always against us[/spoiler] |
|
|
mohan123
Constraint Violating Yak Guru
252 Posts |
Posted - 2012-11-29 : 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 queryP.V.P.MOhan |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-11-29 : 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 queryP.V.P.MOhan
what do you mean by that ? can you illustrate with an example ? KH[spoiler]Time is always against us[/spoiler] |
|
|
mohan123
Constraint Violating Yak Guru
252 Posts |
Posted - 2012-11-29 : 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 comeselect DimConditionDefinitionId ,SUM (CASE WHEN DimConditionDefinitionId = @condition THEN totalusers ELSE 0 END) /246624.0 AS PopulationCount from pop_factGROUP by DimConditionDefinitionIdP.V.P.MOhan |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
|