ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Use SQL statements in Excel VBA to query SQL Server Data Problem (https://www.excelbanter.com/excel-worksheet-functions/6839-use-sql-statements-excel-vba-query-sql-server-data-problem.html)

Thank You

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


All times are GMT +1. The time now is 04:37 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com