case syntax

This is a discussion on case syntax within the PHP Language forums, part of the PHP Programming Forums category; Hi, I've no Mysql NG access from my ISP, so let me ask here. I've a case statement ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-19-2005
Bob Bedford
 
Posts: n/a
Default case syntax

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

Reply With Quote
  #2 (permalink)  
Old 05-19-2005
Alvaro G Vicario
 
Posts: n/a
Default Re: case syntax

*** 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
--
Reply With Quote
  #3 (permalink)  
Old 05-19-2005
Dave
 
Posts: n/a
Default Re: case syntax

Bob Bedford (bedford1@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 <dave@REMOVEbundook.com>
(Remove REMOVE for email address)
Reply With Quote
  #4 (permalink)  
Old 05-19-2005
Dave
 
Posts: n/a
Default Re: case syntax

Dave (dave@REMOVEbundook.com) decided we needed to hear...
> Bob Bedford (bedford1@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 <dave@REMOVEbundook.com>
(Remove REMOVE for email address)
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 11:52 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0