By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,729 Members | 1,340 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,729 IT Pros & Developers. It's quick & easy.

case syntax

P: n/a
Hi,

I've no Mysql NG access from my ISP, so let me ask here.

I've a case statement in mysql.

Here is the code:

select ....,
case myvalue
when 'X' then valueX
when 'Y' then valueY
when 'A' then valueY
when 'B' then valueY

In my case, Y,A and B gave the same value.

I'm trying to do something like:

case myvalue
when 'X' then valueX
when in('Y','A','B') then valueY

But I can't get it to work with IN statement. What's the syntax ?

Bob

Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
*** Bob Bedford wrote/escribió (Thu, 19 May 2005 08:30:54 +0200):
case myvalue
when 'X' then valueX
when in('Y','A','B') then valueY

But I can't get it to work with IN statement. What's the syntax ?


This is the syntax for CASE:

http://dev.mysql.com/doc/mysql/en/ca...t.html#IDX1957
http://dev.mysql.com/doc/mysql/en/co...s.html#IDX1232
--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
Jul 17 '05 #2

P: n/a
Bob Bedford (be******@notforspammershotmail.com) decided we needed to
hear...
Hi,

I've no Mysql NG access from my ISP, so let me ask here.

I've a case statement in mysql. ..... I'm trying to do something like:

case myvalue
when 'X' then valueX
when in('Y','A','B') then valueY

But I can't get it to work with IN statement. What's the syntax ?

Bob

select case when myvalue = 'X' then valueX
when myvalue in ('Y','A','B') then valueY else 'something'

If you don't supply the trailing else then null will be returned if
none of the conditions are satisfied.
--
Dave <da**@REMOVEbundook.com>
(Remove REMOVE for email address)
Jul 17 '05 #3

P: n/a
Dave (da**@REMOVEbundook.com) decided we needed to hear...
Bob Bedford (be******@notforspammershotmail.com) decided we needed to
hear...
Hi,

I've no Mysql NG access from my ISP, so let me ask here.

I've a case statement in mysql.

....
I'm trying to do something like:

case myvalue
when 'X' then valueX
when in('Y','A','B') then valueY

But I can't get it to work with IN statement. What's the syntax ?

Bob

select case when myvalue = 'X' then valueX
when myvalue in ('Y','A','B') then valueY else 'something'

If you don't supply the trailing else then null will be returned if
none of the conditions are satisfied.

My apologies - I'm missing an end from the statement...

select case when myvalue = 'X' then valueX
when myvalue in ('Y','A','B') then valueY else 'something' end

--
Dave <da**@REMOVEbundook.com>
(Remove REMOVE for email address)
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.