Home |
Search |
Today's Posts |
#1
|
|||
|
|||
Use SQL statements in Excel VBA to query SQL Server Data Problem
I try to use SQL satatment to query data from SQL Server but I don't know why I need to increase 2 into the "intDay". If there no 2 increse the day will display is 3 not 5. Who can tell me what problems have. Thanks!
================================================= Public Function SetSQLString(strSQL as String) intYear = 2004 intMonth = 11 intDay = 5 + 2 strReaderName = "'" & Sheet2.Cells(12, 3) & "'" strSQL = " SELECT Name, " _ + " Description, " _ + " Min(Date) as FirstIn, " _ + " Max(Date) as LastOut " _ + " FROM HistoryTable " _ + " WHERE Name = " + strName + _ + " AND DatePart(yyyy,Date) = " + intYear + _ + " AND DatePart(mm,Date) = " + intMonth + _ + " AND DatePart(dd,Date) = " + intDay + _ + " GROUP BY Name, Description" + _ + " ORDER BY Name " End Sub -- Ronald |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Excel 2003 FAILS, but Excel 2000 SUCCEEDS ??? | Excel Discussion (Misc queries) | |||
External data Macro Problem Excel 97 | Excel Discussion (Misc queries) | |||
How to use a Access Query that as a parameter into Excel database query | Excel Discussion (Misc queries) | |||
Problem with data using IF and Nested IF statements possibly??? | Excel Discussion (Misc queries) | |||
stop excel from shifting cells up when a query returns no data | Excel Worksheet Functions |