|
-
Mar 27th, 2008, 09:55 AM
#1
Thread Starter
Fanatic Member
excel vba sql query help
hi ,how to change the sql query date between as below startdate and enddate string??i want to use date between query from excel vba to retrieve data from sql server.please help.thanks.
Code:
Dim enddate As String
Dim startdate As String
Dim partno As String
partno = ComboBox1.Text
startdate = Format(Dtpdata.DTPicker1.Value, "dd MMM yyyy")
enddate = Format(Dtpdata.DTPicker1.Value, "dd MMM yyyy")
“SELECT SpcData.PartNo, SpcData.Dimension, SpcData.MachineNo, SpcData.Date FROM SPC.dbo.SpcData SpcData WHERE (SpcData.Date Between {ts '2008-03-24 00:00:00'} And {ts '2008-03-27 00:00:00'}) AND (SpcData.PartNo='" & partno & "') GROUP BY SpcData.PartNo, SpcData.Dimension, SpcData.MachineNo, SpcData.Date
-
Mar 27th, 2008, 11:25 AM
#2
Re: excel vba sql query help
Are the dates in question in a specific cell on a specific worksheet?
-
Mar 27th, 2008, 07:02 PM
#3
Thread Starter
Fanatic Member
Re: excel vba sql query help
Hack:
hi,thanks reply.The date is from the sql database table field.
for example:i want to retrieve the data from 23-03-2008 to 28-03-08.so i use 2 dtpicker to retrieve the data from the sql server to the excel worksheet.
i just want to know how to change the sql query of date use the dtpicker select date.
(SpcData.Date Between {ts '2008-03-24 00:00:00'} And {ts '2008-03-27
00:00:00'})
please help.
-
Mar 28th, 2008, 02:55 AM
#4
Re: excel vba sql query help
Everything you need to know (and based on your previous threads, should know already) is in two articles from our Database Development FAQs/Tutorials (at the top of this forum):
-
Mar 28th, 2008, 09:04 AM
#5
Thread Starter
Fanatic Member
Re: excel vba sql query help
hi,thank ya reply.the previous problem has been solved.but then i face another problem is using "where statement as below statement cannot to sql the query have error message "type mismatch'
this is the current code:
Code:
"SELECT SpcData.PartNo, SpcData.Dimension, SpcData.MachineNo, Sum(SpcData.SampleNo/5) AS 'Sum'" & Chr(13) & "" & Chr(10) & "FROM SPC.dbo.SpcData SpcData WHERE (SpcData.PartNo='" & partno & "')and (SpcData.Date BETWEEN '" & startdate & "' and '" & enddate & "')GROUP BY SpcData.PartNo, SpcData.Dimension, SpcData.MachineNo " _
this is the previous work able statement is without date between query
Code:
"SELECT SpcData.PartNo, SpcData.Dimension, SpcData.MachineNo, Sum(SpcData.SampleNo/5) AS 'Sum'" & Chr(13) & "" & Chr(10) & "FROM SPC.dbo.SpcData SpcData WHERE (SpcData.PartNo='" & partno & "')GROUP BY SpcData.PartNo, SpcData.Dimension, SpcData.MachineNo " _
please help.thanks.
-
Mar 28th, 2008, 09:20 AM
#6
Re: excel vba sql query help
That should be fine for SQL Server, as long as startdate and enddate are formatted appropriately (what you showed in your first post will fail if the client OS language is not English).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|