Anyone actually get Case statement to work ... ?

F

ForestFeeder

Has anyone successfully used the Case statement in a select query using MS
SQL within Excel , looking at an excel file as a datasource?

I'd love for you to post a sample query that you got to work. I've followed
the syntax every which way and it doesnt seem to work on this configuration.
Much appreciated !
 
W

William Horton

Not sure if this is what you want/need but it works for me in a macro.

Sub test()
Dim MWS As Worksheet, X As String
Set MWS = ThisWorkbook.Worksheets(1)
Select Case MWS.Range("A1")
Case 1
MsgBox "case was 1"
Case 2
MsgBox "case was 2"
Case 3
MsgBox "case was 3"
Case Else
MsgBox "case was not 1 or 2 or 3"
End Select
End Sub

Hope that is a start.
 
F

ForestFeeder

Thanks Bill,
Unfortunately I need to use SQL in Microsoft Query within Excel.

I have an excel file ( A ) which acts as a database. Another excel file ( B
) is a report that queries the database ( A ).

My SQL query requires the use of a case statement.
 
D

Duke Carey

Until you posted this I hadn't tried. However, now that I've tried it isn't
looking so good. A simple case select that runs fine in SQL Server Query
Analyzer returns no records when run against an Excel file containing the
same SQL data.

I can't even get MS Query to accept a rudimentary CASE statement
 
Top