SQLTeam.com | Weblogs | Forums

Skip Condition


#1

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.
Thanks


#2

select case when A='POP' then 1 end


#3

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


#4

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?


#5

Hi Madivanan

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


#6

Ok. Have you tried the code I provided?


#7

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


#8

@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.

Thanks


#9

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

table2
tid def
1 AAA
2 BBB
3 CCC


#10

Try This

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


#11

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


#12

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?


#13

yes Viggneshwar


#14

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