Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Thank You
 
Posts: n/a
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2003 FAILS, but Excel 2000 SUCCEEDS ??? Richard Excel Discussion (Misc queries) 2 May 13th 23 11:46 AM
External data Macro Problem Excel 97 Craig Kelly Excel Discussion (Misc queries) 1 January 17th 05 03:17 PM
How to use a Access Query that as a parameter into Excel database query Karen Middleton Excel Discussion (Misc queries) 1 December 13th 04 07:54 PM
Problem with data using IF and Nested IF statements possibly??? Ajay Excel Discussion (Misc queries) 2 December 9th 04 09:23 AM
stop excel from shifting cells up when a query returns no data DrLostinExcel Excel Worksheet Functions 2 November 9th 04 05:44 PM


All times are GMT +1. The time now is 12:43 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"