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
|