Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 "Or" Error

Author  Topic 

paull
Yak Posting Veteran

50 Posts

Posted - 2009-07-01 : 05:33:37
Hi Guys

Can someone please tell me what is wrong with this code? I have tried moving brackets around and it works if I drop the "OR".

Case when (Q30a_Adj_Pedals = ' ' AND Version = ('1' OR '2')) then '0' end

Thanks

P

rajdaksha
Aged Yak Warrior

595 Posts

Posted - 2009-07-01 : 05:47:13

SELECT
CASE WHEN (Q30A_ADJ_PEDALS = ' ' AND VERSION IN ('1','2')) THEN '0' END
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-07-01 : 05:48:13
AND (Version='1' OR Version='2')

Also should be possible
AND Version in ('1','2')

Fred


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

paull
Yak Posting Veteran

50 Posts

Posted - 2009-07-01 : 05:59:54
Aha!! Thanks guys

Everyday is a school day as they say!!
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-07-01 : 06:17:48
welcome


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

paull
Yak Posting Veteran

50 Posts

Posted - 2009-07-01 : 06:30:17
Hello again chaps

The code works but it is not doing what I had hoped for!! The code is basically saying If Q30A_AdJ_Pedals is blank AND version is either 1 or 2 make Q30a_ADJ_PEDAL = "0". When I run my code it changes everything to NULL!!!

Any ideas what I might be doing wrong here?

Many thanks
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2009-07-01 : 11:51:53
You did not enclude an ELSE clause so every row that doesn't meet that criteria is going to retun NULL.
quote:
Originally posted by rajdaksha


SELECT
CASE WHEN (Q30A_ADJ_PEDALS = ' ' AND VERSION IN ('1','2')) THEN '0'
ELSE Q30A_ADJ_PEDALS
END


Go to Top of Page
   

- Advertisement -