Query an Excel file using CASE statement

ruve1k

Board Regular
Joined
Aug 31, 2008
Messages
171
I have a query which uses another excel file as the data source. When I add a CASE statement to the query I get the following error: "syntax error (missing operator) in query expression"
The syntax I used is as follows:
Code:
case when column1 = 'Other' then column2 else column1 end as MyColumn
Apparently there are issues with using a CASE statement in a query that targets an excel file.
What is the syntax for a conditional statement in the SELECT clause of a SQL query which targets an excel file?
Thanks!
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
I think it's case variable when value rather than case when variable=value. Try:-
Code:
case column1 when 'Other' then column2 else column1 end as MyColumn

For two values, use IIF:-
Code:
IIF(column1 = 'Other', column2, column1) as MyColumn
 
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,543
Members
452,924
Latest member
JackiG

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