Groups | Blog | Home
all groups > sql server connect > november 2004 >

sql server connect : Use SQL statements in Excel VBA to query SQL Server Data Problem


Thank You
11/20/2004 8:48:06 PM
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

v-jalim NO[at]SPAM online.microsoft.com
11/30/2004 12:34:10 AM
Sounds like the problem you are having is due to the results not being
returned according to the criteria you specify. Is this what you are having
problems with? If you have Query Analyzer or MSQuery, you might to run your
SQL select statement from those clients to see what results it is returning
you. This will mean that you have to hard code the parameter values in your
criteria. So, test your resultset from Query Analyzer or MSQuery and make
sure it is correct before coding it in VBA. Otherwise highlight the problem
you have with a few sample records and what results you are seeing.

-- james

***Disclaimer: This posting is provided "as is" with no warranties and
confers no rights.***
--------------------
[quoted text, click to view]
cpmsftngxa10.phx.gbl!TK2MSFTFEED02.phx.gbl!tornado.fastwebnet.it!tiscali!new
sfeed1.ip.tiscali.net!fi.sn.net!newsfeed2.fi.sn.net!newsfeed.bahnhof.se!195.
197.54.117.MISMATCH!feeder1.news.jippii.net!news.net.hanse.com!nntp.gblx.net
!nntp3.phx1!news.hgc.com.hk!not-for-mail
[quoted text, click to view]
AddThis Social Bookmark Button