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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
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,213,537
Messages
6,114,216
Members
448,554
Latest member
Gleisner2

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