473,385 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

using case, Valid statement?

Is this a valid sql statement:

SELECT
case field1
when 'first' then 1
when 'second' then 1
else null
end
FROM mytable

Mike
Jul 19 '05 #1
3 4466
I can use decode like:

decode(
field1,'first',1,
decode(field1,'second',2,0
)
)

except that this has to be all nested and is very hard to work with. If
I have nine items it becomes very ugly.

Michael Hill wrote:

Is this a valid sql statement:

SELECT
case field1
when 'first' then 1
when 'second' then 1
else null
end
FROM mytable

Mike

Jul 19 '05 #2
I can use decode like:

decode(
field1,'first',1,
decode(field1,'second',2,0
)
)

except that this has to be all nested and is very hard to work with. If
I have nine items it becomes very ugly.

Michael Hill wrote:

Is this a valid sql statement:

SELECT
case field1
when 'first' then 1
when 'second' then 1
else null
end
FROM mytable

Mike

Jul 19 '05 #3
Michael Hill <hi****@ram.lmtas.lmco.com> wrote in message news:<40***************@ram.lmtas.lmco.com>...
I can use decode like:

decode(
field1,'first',1,
decode(field1,'second',2,0
)
)


You don't have to nest :

decode(field1,
'first',1,
'second',2,
'third',3,
null)

It can go up to 255 arguments, I think?

Is this a valid sql statement:

SELECT
case field1
when 'first' then 1
when 'second' then 1
else null
end
FROM mytable


In 9i it is valid syntax.
In 8i you can use :

case
when field1='first' then 1
when field1='second' then 2
else null
end

The good thing about this syntax is, that each when clause can have
widely different boolean expressions.

In short:

In 8i you use decode syntax if it's just a case of different values
for a column, and use case syntax for more complicated expressions.

In 9i you use the same constructs, but they added the simplified case
syntax (the one you ask if it's valid) as an alternative to decode.
/KiBeHa
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Andy | last post by:
Can someone tell me if the following Switch...Case construct is valid? I'm wanting to check for multiple values in the Case statement without explicitly listing each values. So for example, will...
5
by: Colleyville Alan | last post by:
I have built a SQL statement that is trying to loop through the fields of a table that was built from a spreadsheet and hence is "short and fat". So rather than hard-coding, I have a loop from...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
25
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...
5
by: Frederick Dean | last post by:
Hi,guys! I'm reading Stephen Dewhurst's book "C++ Gotchas"£¬in gothca #7, I meet a weird case: bool Postorder::next() { switch (pc) case START: while (true) if (!child()) { pc = LEAF; return...
1
by: Thiero | last post by:
Hi I posted s thread but did have any reply, I am a new programmer and really wants someone to help me on how to use TreeMap for this code cos I want to it to be able to handle the options from 6...
7
by: christian.eickhoff | last post by:
Hi Everyone, I am currently implementing an XercesDOMParser to parse an XML file and to validate this file against its XSD Schema file which are both located on my local HD drive. For this...
9
by: Robbie Hatley | last post by:
Greetings, group. I just found a weird problem in a program where a variable declared in a {block} after a "case" keyword was being treated as having value 0 even though its actual value should...
3
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
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.