Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a comma in the default param of DECODE

Status
Not open for further replies.

mamabird

Programmer
Dec 19, 2006
15
US
I am using the DECODE function and my default value has a comma. When I run the query, it's cutting off everything after the comma in my default. How can I get the entire string returned?

SELECT DECODE (
mycol, '1', 'One',
'2', 'Two',
'3', 'Three',
'This, is the default') AS myval
FROM mytable

The query returns only "This" as the default. Thanks!
 
Mama,

There is something else going on here. Your code works just as expected:
Code:
select * from mytable;

MYCOL
-----
    1
    2
    3
    4

SELECT DECODE (
mycol, '1', 'One',
           '2', 'Two',
           '3', 'Three',
           'This, is the default') AS myval
FROM mytable
/

MYVAL
--------------------
One
Two
Three
This, is the default
To troubleshoot this issue, could you please issue this SQL*Plus command prior to re-running your code:
Code:
clear columns
Once you re-run your code, let us know if your results change.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
 
Thanks Dave/Mufasa/Santa. I should have troubleshooted (is that even a word?) this better. I am able to successfully run this DECODE statement in Toad, it gives me the results I am looking for.

Where it's breaking is in ColdFusion. I have the code there (the exact same statement as in Toad) but when I run it using a browser, it takes everthing after the comma and moves it to the next line (I'm using this to populate a dropdown list.)

This is the actual statement I'm using in my code:

Code:
SELECT last_name || DECODE(first_name, 'NA', '', ' ,'||first_name) AS name

I am wanting to list people by last name, first name unless the value is NA - I don't want to display NA, NA. This is what I should get:

Code:
NA
Grouch, Oscar
Smith, Tom

But instead I'm getting:

Code:
NA
Grouch
Oscar
Smith
Tom

Unless you have any insight as to why CF (or browser rendering) is doing this, I will post this question in the CF forum.

Thanks!
mamabird
 
The word you want is "troubleshot" [smile].

I would post the problem in the ColdFusion forum since this is obviously a deficiency of that software. Once they help resolve the problem there, please be sure to come back to this thread and post the resolution.

[cheers]

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top