SQLTeam.com | Weblogs | Forums

Skip Condition


Dear All
I have a query where having condition A='POP' AND B=1.
The value '1' appears to B column when 'A' value is equal to 'POP' only , otherwise 'B' shouldn't have any values.
'B' is a integer data type column.

Please help me on this.


select case when A='POP' then 1 end


Then what value get pass if A<>'POP'.
If A<>'POP , I need to pass all values to B


Try this

select case when A='POP' then 1 else B end as B from table

Or Can you post some sample data with expected result?


Hi Madivanan

Actualy the B take multiple values from a table (which consist data 1...10).


Ok. Have you tried the code I provided?


FROM table1
WHERE (A = @A AND @A <> 'POP' OR B=1)


@Madhivanan- yes, It process when A='POP' only and not taking other values from table when A<>'POP'

This is how my query looks alike

select ...... from table1
where tid= (case when @para='pop' then 1 else end)

table1 table2
tid value tid def
1 10 1 AAA
2 15 2 BBB
3 20 3 CCC
1 16
2 25

tid is connector for both table.
when @para is 'pop' then i have to pass only 1 as tid and if its not 'pop then I need to pass 1,2,3 for tid field.



tid value
1 10
2 15
3 20
1 16
2 25

tid def


Try This

select ...... from table1where tid= (case when @para='pop' then 1 else tid end)


Thanks for your reply Viggnesh..

As per yours it won't take other values if @para='pop' .
NULL value only get pass to else condition when @para<>'pop


No Romo....
If @para is pop then you should return records having tid is 1.
if @para is not pop then you should return all the records from the table.
is this is the case?


yes Viggneshwar


then (case when @para='pop' then 1 else tid end) this condition should work. incase of null please use isnull