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

Switch Commad in MS Access

I looked at a previous post and it mentioned the following script that would decode the data value:
"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."

My hurdle is that in the above code I want the retrieved data to keep its original value if it does not fall under 1,2, or 3, rather than changing it to "unknown"
how would i accomplish this?

Thanks in advance for the help.
Nov 29 '06 #1
6 2492
NeoPa
32,556 Expert Mod 16PB
As ITEM_DESCR is a newly created field it can't have an original value.
Any value you want to set as the 'unset' value would simply replace the value 'Unknown' in the string though.
Nov 30 '06 #2
Thank you for the reply. I did try this, however, it not only changes everything to 'UNKNOWN', but also the values for 1, 2 and 3 get changed to 'UNKNOWN'.

I did check the table, and it does contain 1, 2, and 3, so the query should not have any reason to change all of the values to 'UNKNOW'.
Nov 30 '06 #3
NeoPa
32,556 Expert Mod 16PB
If you post the SWITCH part of your code, I'm sure there must be some sort of mistake in it as that shouldn't happen.
Alternatively, look more closely at it and the original to make sure they are similar in all respects but that.
Nov 30 '06 #4
Thank you again for your prompt reply. So I figured that I need to use the Case statement rather than the Switch function to accomplish my task. However, when I do use the following case statement, I get an error in Access stating that i'm missing an operator in my query.

Here is my syntax:

SELECT (Case when tblSiteIDs.SiteCountryCode = 'BEFR' then 'BE' elseif Case when tblSiteIDs.SiteCountryCode = 'BENL' then 'BE' else tblSiteIDs.SiteCountryCode end)

So in the above statment I'm trying to change every instance of "BEFR" and "BENL" to "BE" and leave all of the other CountryCode as is...
Nov 30 '06 #5
Found my answer...this is the syntax i was looking for

Select IIF( tblSiteIDs.SiteCountryCode In("BEFR", "BENL"), "BE",
tblSiteIDs.SiteCountryCode) As Country from tblSiteIDs

Thanks again for all the help.

Regards,


Thank you again for your prompt reply. So I figured that I need to use the Case statement rather than the Switch function to accomplish my task. However, when I do use the following case statement, I get an error in Access stating that i'm missing an operator in my query.

Here is my syntax:

SELECT (Case when tblSiteIDs.SiteCountryCode = 'BEFR' then 'BE' elseif Case when tblSiteIDs.SiteCountryCode = 'BENL' then 'BE' else tblSiteIDs.SiteCountryCode end)

So in the above statment I'm trying to change every instance of "BEFR" and "BENL" to "BE" and leave all of the other CountryCode as is...
Dec 1 '06 #6
NeoPa
32,556 Expert Mod 16PB
Are we talking about SQL Server here?
Your code looks like that.
I was suggesting a standard Access answer.
Pleased you've got a solution anyway.
Dec 1 '06 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Rudi Hansen | last post by:
I dont seem to be able to find the switch statement in Python. I would like to be able to do switch(var) case 1 : print "var = 1" case 2: print "var = 2"
35
by: Thomas Matthews | last post by:
Hi, My son is writing a program to move a character. He is using the numbers on the keypad to indicate the direction of movement: 7 8 9 4 5 6 1 2 3 Each number has a direction except...
3
by: Mike Wiseley | last post by:
I created a desktop shortcut with "C:\Program Files\Microsoft Office\MSAccess.exe" "C:\My Documents\CopyAToB.mdb" /pwd "password: The trouble is that when running this shortcut, it prompts first...
2
by: Tom Morgan | last post by:
Hi everyone, I'm having a brain freeze today so if the answer is a misplacced comma or a missing command, I would be happy. What I want to do is use access to return results via an .asp page. ...
2
by: jr | last post by:
I have a niggle with the Switch function I have a querey which has a column with 3 digit values of which there are about 20 which are unique. These are meaningless to the user and so using...
0
by: Pegaso | last post by:
Hi... I have created a utility library with VC++ 7.1 which is used by a VB 6 client. The library creates a secondary thread of execution in order to listen for connections on a socket. The...
3
by: prakashwadhwani | last post by:
When my application starts 2 toolbars still remain open 1) Form View and 2) Formatting (Form/Report) Toolbar Also ... Access's default Menu-Bar also remains open. How to switch it off at...
20
by: Ryan Liu | last post by:
Hi, I have a client/server application, using one thread/client approach. I see very high context switch/sec. What are the ways to reduce it? Each thread sleep longer in its endless loop if...
9
by: Gordon | last post by:
I want to add a feature to a project I'm working on where i have multiple users set up on my Postgres database with varying levels of access. At the bare minimum there will be a login user who...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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
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
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
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.