MS Query Case Statement

MattConnell

New Member
Joined
Feb 23, 2011
Messages
1
All,

Hope you can help here.

Excel 2010 using MS Query to run handcoded SQL to ruturn data from an ORACLE 11G DBMS.

I am trying to use a CASE statement but am confounded with a series of errors that I cannot figure out.

SELECT
GORIMMU.GORIMMU_PIDM,
GORIMMU.GORIMMU_IMMU_CODE,
CASE
WHEN
(GORIMMU.GORIMMU_IMMU_CODE = 'IMMU_PEND')
THEN 'Y'
ELSE 'N'
END AS 'IMMU_PEND_IND',
FROM GENERAL.GORIMMU GORIMMU


This is what I want to run, however every time I do I get some permutation of the "Didnt expect XX after the select column list" where XX is either WHERE or ( or GORIMMU (if i remove the parenthesis from the logic statement)

Any assistance here.....rather new at this so I'm los here.

Matt.
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
I'm not sure that the MSQuery ODBC driver will allow CASE statements. Probably not, based on your experience. Maybe just pull in the IMMU Code and then update it to Y or N after it's in Excel.
 
Upvote 0
Matt

I think xenou is right about the CASE thing, but it might be possible to do what you want in the query - though it might be easier to just do the Excel thing.

What I was thinking was that since your CASE statement is simply checking if the field is 'IMMU_PEND' and returning Y/F you could try an IIf statement.

Or even simply something like this.

SELECT GORIMMU.GORIMMU_PIDM, GORIMMU.GORIMMU_IMMU_CODE,
(GORIMMU.GORIMMU_IMMU_CODE = 'IMMU_PEND') AS 'IMMU_PEND_IND',
FROM GENERAL.GORIMMU GORIMMU

That won't return Y/N, not sure what it returns for Oracle but for Access it returns -1 for true and 0 for false.

Actually, I just tested the Iif and it works for Access but again I'm not sure about Oracle.

IIf(GORIMMU.GORIMMU_IMMU_CODE='IMMU_PEND', 'Y', 'N') As 'IMMU_PEND_IND'
 
Upvote 0
You have a comma after the SELECT CASE statement and also I suspect you want to surround the column nam,e with square brackets:

Rich (BB code):
SELECT 
GORIMMU.GORIMMU_PIDM, 
GORIMMU.GORIMMU_IMMU_CODE,
CASE
WHEN
(GORIMMU.GORIMMU_IMMU_CODE = 'IMMU_PEND')
THEN 'Y'
ELSE 'N'
END AS [IMMU_PEND_IND] 
FROM GENERAL.GORIMMU GORIMMU
 
Upvote 0

Forum statistics

Threads
1,224,566
Messages
6,179,551
Members
452,927
Latest member
rows and columns

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top