0

inside an SQL SELECT CASE STATEMENT how would i check if the a value for some coulmn in sometable is equal to 0 where the id is equal to something?

user1570048
  • 880
  • 6
  • 35
  • 69
  • 1
    Can you post an example statement. The answers that involve a sub query inside the case statement will work, but are likely to perform poorly. There may be a better way to get your result. – Tobsey Oct 19 '12 at 11:27

3 Answers3

3
select
    case
        when (select column_name from sometable where id = @id) = 0 then
        else 
    end
Roman Pekar
  • 107,110
  • 28
  • 195
  • 197
2
select 
 case when( select column from table where id=333)=0 then "your condition"
else
end
SRIRAM
  • 1,888
  • 2
  • 17
  • 17
1

My interpretation of your question:

SQL check if numerical value is 0 for a field (Field1) [only] when id is=333
[If id is not 333, don't need to check]

SELECT CASE WHEN isnull(id,0) <> 333 OR Field1=0 THEN 1 ELSE 0 END
      ,other1, other2
  FROM tbl
RichardTheKiwi
  • 105,798
  • 26
  • 196
  • 262