473,480 Members | 2,347 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

Jul 17 '05 #1
3 2758
*** 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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
4875
by: Dave | last post by:
I am getting a syntax error on Select Case Now Case > "2/2/2004 12:30:00 AM" response.redirect "votingover.asp" case else m=0 End Select
9
3611
by: Kevin | last post by:
Hi, I am getting a syntax error Microsoft VBScript compilation error '800a03ea' Syntax error On the code below. The error references the "End Select" line Can anyone help me with what I am...
3
4468
by: Michael Hill | last post by:
Is this a valid sql statement: SELECT case field1 when 'first' then 1 when 'second' then 1 else null end FROM mytable
8
3760
by: Penny | last post by:
Hi all, My browser throws this Select Case block back at me pointing out a syntax error on the line: 'Case < 251', between the word 'Case' and the '<' symbol. *************************** ...
2
13569
by: Marco Lazzeri | last post by:
What about a SELECT syntax like that? SELECT CASE WHEN bar.foo_id IS NULL THEN bar.* ELSE foo.* FROM foo, bar Anyway, I need a SELECT query that gets data from a FIRST TABLE if a specific...
15
3481
by: Benny Raymond | last post by:
I'm confused as to how fallthrough is limited in switch. For example the following works: string switch_test = "a"; switch (switch_test) { case "a": case "b": case "c": doSomething(a);
25
4307
by: CJM | last post by:
I'm getting a syntax error with a Select Case statement: Select Case CSng(rs.fields("Field1")) Case 0 Response.Write "Test1" Case Is < 0 <<< Syntax Error...
2
5221
enfuego
by: enfuego | last post by:
Hey kids, got a problem. Here's the code: Rev.techCompany CASE WHEN techCompany LIKE 'North_IR' THEN 'NorthIR' WHEN techCompany LIKE 'South_IR' THEN 'SouthIR' WHEN techCompany LIKE...
2
1980
by: arunmenon | last post by:
Dear Folks, I have an query which something looks like this select ILTRDJ AS YEAR, DATEPART(MONTH,ILTRDJ) AS MONTH, FMSTR.IMITM AS CODE,FMSTR.IMSRP6_UDC AS DESCRIPTION, FTRANS.ILDCT = CASE...
56
6648
by: Adem | last post by:
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" The C++ Standard (ISO/IEC 14882, Second edition, 2003-10-15) says under...
0
7054
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7097
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6750
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6993
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5353
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4493
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3003
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2993
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.