close

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 !

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(quot;A1quot;)
Case 1
MsgBox quot;case was 1quot;
Case 2
MsgBox quot;case was 2quot;
Case 3
MsgBox quot;case was 3quot;
Case Else
MsgBox quot;case was not 1 or 2 or 3quot;
End Select
End Sub

Hope that is a start.

quot;ForestFeederquot; wrote:

gt; Has anyone successfully used the Case statement in a select query using MS
gt; SQL within Excel , looking at an excel file as a datasource?
gt;
gt; I'd love for you to post a sample query that you got to work. I've followed
gt; the syntax every which way and it doesnt seem to work on this configuration.
gt; Much appreciated !

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.

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
quot;ForestFeederquot; wrote:

gt; Has anyone successfully used the Case statement in a select query using MS
gt; SQL within Excel , looking at an excel file as a datasource?
gt;
gt; I'd love for you to post a sample query that you got to work. I've followed
gt; the syntax every which way and it doesnt seem to work on this configuration.
gt; Much appreciated !

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 software 的頭像
    software

    software

    software 發表在 痞客邦 留言(0) 人氣()