473,395 Members | 1,949 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,395 software developers and data experts.

SQL DECODE FUNCTION

MP
I have the following command.

SELECT A.STORE_NAME, A.STORE_NUM, A.ZIP_CODE, B.EMPLOYEE_ID, B.GENDER,
B.EMP_LEVEL, C.ITEM_CODE,
DECODE(B.ITEM_CODE,1, 'CHICK_BURGERS') ITEM_DESCR,
DECODE(B.ITEM_CODE,2, 'HAM_BURGERS') ITEM_DESCR,
DECODE(B.ITEM_CODE,3, 'PIZZAS') ITEM_DESCR
FROM
STORE_DETAIL A,
EMP_DETAIL B,
ITEM_DETAIL C
WHERE A.STORE_CODE = B.STORE_CODE AND
B.EMP_ID = C.EMP_ID

But I want the output as where ever there is 1 under Item code column,
in the next column corresponding to it I want CHICK_BURGERS under Item
description column. Similarly where ever there is 2 under Item code
column there has to be HAM_BURGERS under item description column and so
on and so forth. But right now with the above command I am getting 3
item description columns where as I want only one item description
column.
Can someone please tell me how do I do this?

Thank you.
MP

Mar 3 '06 #1
1 35753
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

There isn't a DECODE() function in Access SQL. I don't know exactly
what DECODE() does, but from your question and the way the DECODE
expression looks, I'm guessing it can be translated to a Switch()
function, like this:

SELECT A.STORE_NAME, A.STORE_NUM, A.ZIP_CODE, B.EMPLOYEE_ID, B.GENDER,
B.EMP_LEVEL, C.ITEM_CODE,
Switch(B.ITEM_CODE=1, 'CHICK_BURGERS',
B.ITEM_CODE=2, 'HAM_BURGERS',
B.ITEM_CODE=3, 'PIZZAS',
B.ITEM_CODE NOT IN (1,2,3), 'UNKNOWN') ITEM_DESCR
FROM ... etc.

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBRAihu4echKqOuFEgEQISAgCfQL8lMRg5zxyyVFhtWU1KjN xvvyIAoOTU
1ddTddi38ZdAb9xxerTcap2E
=VF8d
-----END PGP SIGNATURE-----

MP wrote:
I have the following command.

SELECT A.STORE_NAME, A.STORE_NUM, A.ZIP_CODE, B.EMPLOYEE_ID, B.GENDER,
B.EMP_LEVEL, C.ITEM_CODE,
DECODE(B.ITEM_CODE,1, 'CHICK_BURGERS') ITEM_DESCR,
DECODE(B.ITEM_CODE,2, 'HAM_BURGERS') ITEM_DESCR,
DECODE(B.ITEM_CODE,3, 'PIZZAS') ITEM_DESCR
FROM
STORE_DETAIL A,
EMP_DETAIL B,
ITEM_DETAIL C
WHERE A.STORE_CODE = B.STORE_CODE AND
B.EMP_ID = C.EMP_ID

But I want the output as where ever there is 1 under Item code column,
in the next column corresponding to it I want CHICK_BURGERS under Item
description column. Similarly where ever there is 2 under Item code
column there has to be HAM_BURGERS under item description column and so
on and so forth. But right now with the above command I am getting 3
item description columns where as I want only one item description
column.
Can someone please tell me how do I do this?

Mar 3 '06 #2

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

Similar topics

1
by: Walt | last post by:
Hi, I want to write a query that returns Y or N depending on whether the current time is within a specified window i.e. EVENT_TABLE ---------- event_id number PK event_start date...
2
by: Mark Hoffman | last post by:
I'm a newbie at Oracle..Be gentle! I have a table that stores information (WMI data) about computers on our network. The table looks like: ComputerID ItemID Class Property Value
10
by: N | last post by:
What is the function in SQL that works like DECODE in Oracle?" Thanks, N
4
by: Newbie | last post by:
How would I modify this form to encode *all* the characters in the 'source' textarea to the '%xx' format & place result code into the 'output' textarea? (cross browser compatable) Any help is...
2
by: Amin Schoeib | last post by:
Hi, Like I see there is no equivalent to the Oracle decode Function In Postgres.Is there maybe somebody who wrote decode as a Function? Schoeib 4Tek Gesellschaft für angewandte...
3
by: Guoqi Zheng | last post by:
Dear sir, I need to decode base64 encoded email. I used below function but it does not work correctly, especially when I need to decode some Characters like Chinese, Can some one point out...
2
by: rsd | last post by:
Hi, I'm trying get Samsung YH-920 mp3 player to work with Debian GNU/Linux. To do that I need to run http://www.paul.sladen.org/toys/samsung-yh-925/yh-925-db-0.1.py script, the idea behind the...
1
by: Deven Oza | last post by:
Hello everyone Please help me for the following query I want to solve the query Using the (DECODE) function, I want to write a program segment that will successfully decode all the CIS courses...
16
by: Medhatithi | last post by:
Hi, I am facing a strange problem with decode function in oracle. My table name is status_hist. Below is the query I am hitting on this table: select...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
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
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,...

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.