case syntax

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bob Bedford

    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

  • Alvaro G Vicario

    #2
    Re: case syntax

    *** Bob Bedford wrote/escribió (Thu, 19 May 2005 08:30:54 +0200):[color=blue]
    > 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 ?[/color]

    This is the syntax for CASE:





    --
    -- Á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
    --

    Comment

    • Dave

      #3
      Re: case syntax

      Bob Bedford (bedford1@notfo rspammershotmai l.com) decided we needed to
      hear...[color=blue]
      > Hi,
      >
      > I've no Mysql NG access from my ISP, so let me ask here.
      >
      > I've a case statement in mysql.[/color]
      .....[color=blue]
      > 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
      >
      >[/color]
      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@REMOVEbun dook.com>
      (Remove REMOVE for email address)

      Comment

      • Dave

        #4
        Re: case syntax

        Dave (dave@REMOVEbun dook.com) decided we needed to hear...[color=blue]
        > Bob Bedford (bedford1@notfo rspammershotmai l.com) decided we needed to
        > hear...[color=green]
        > > Hi,
        > >
        > > I've no Mysql NG access from my ISP, so let me ask here.
        > >
        > > I've a case statement in mysql.[/color]
        > ....[color=green]
        > > 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
        > >
        > >[/color]
        > 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.
        >[/color]
        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@REMOVEbun dook.com>
        (Remove REMOVE for email address)

        Comment

        Working...