PC Review


Reply
Thread Tools Rate Thread

Adding a date parameter to an SQL statement

 
 
blake7
Guest
Posts: n/a
 
      30th Oct 2008
Hi all, I have the following SELECT statement as below but want to add a date
parameter, where in the statement do I add it ?? can anyone help - I keep
trying different places but it returns errors - Thank You

SELECT Count([Main Audit Data].[Boiler Type]) AS [Number of faults], [Main
Audit Data].[Boiler Type], [Main Audit Data].Status
FROM [Main Audit Data]
WHERE ((([Main Audit Data].[Boiler Type]) Like "*isar*")) AND ([Main Audit
Data].Status="warranty")
GROUP BY [Main Audit Data].[Boiler Type], [Main Audit Data].Status;

Include this date parameter where ?????
HAVING ((([Main Audit Data].[Audit Date]) Between #1/1/2008# And
#31/01/2008#))
 
Reply With Quote
 
 
 
 
John Spencer
Guest
Posts: n/a
 
      30th Oct 2008
Include that as part of the where clause.

SELECT Count([Main Audit Data].[Boiler Type]) AS [Number of faults]
, [Main Audit Data].[Boiler Type]
, [Main Audit Data].Status
FROM [Main Audit Data]
WHERE [Main Audit Data].[Boiler Type] Like "*isar*"
AND [Main Audit Data].Status="warranty"
AND [Main Audit Data].[Audit Date] Between #1/1/2008# And
#31/01/2008#
GROUP BY [Main Audit Data].[Boiler Type]
, [Main Audit Data].Status;

By the way, I would enter the dates in yyyy-mm-dd format or in the US format
of mm/dd/yyyy.

See the following for an explanation of why.
International Dates in Access at:
http://allenbrowne.com/ser-36.html

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County

blake7 wrote:
> Hi all, I have the following SELECT statement as below but want to add a date
> parameter, where in the statement do I add it ?? can anyone help - I keep
> trying different places but it returns errors - Thank You
>
> SELECT Count([Main Audit Data].[Boiler Type]) AS [Number of faults], [Main
> Audit Data].[Boiler Type], [Main Audit Data].Status
> FROM [Main Audit Data]
> WHERE ((([Main Audit Data].[Boiler Type]) Like "*isar*")) AND ([Main Audit
> Data].Status="warranty")
> GROUP BY [Main Audit Data].[Boiler Type], [Main Audit Data].Status;
>
> Include this date parameter where ?????
> HAVING ((([Main Audit Data].[Audit Date]) Between #1/1/2008# And
> #31/01/2008#))

 
Reply With Quote
 
blake7
Guest
Posts: n/a
 
      30th Oct 2008
Brilliant - Thanks John, I knew there was a way round it, but just could not
see it.

"John Spencer" wrote:

> Include that as part of the where clause.
>
> SELECT Count([Main Audit Data].[Boiler Type]) AS [Number of faults]
> , [Main Audit Data].[Boiler Type]
> , [Main Audit Data].Status
> FROM [Main Audit Data]
> WHERE [Main Audit Data].[Boiler Type] Like "*isar*"
> AND [Main Audit Data].Status="warranty"
> AND [Main Audit Data].[Audit Date] Between #1/1/2008# And
> #31/01/2008#
> GROUP BY [Main Audit Data].[Boiler Type]
> , [Main Audit Data].Status;
>
> By the way, I would enter the dates in yyyy-mm-dd format or in the US format
> of mm/dd/yyyy.
>
> See the following for an explanation of why.
> International Dates in Access at:
> http://allenbrowne.com/ser-36.html
>
> John Spencer
> Access MVP 2002-2005, 2007-2008
> The Hilltop Institute
> University of Maryland Baltimore County
>
> blake7 wrote:
> > Hi all, I have the following SELECT statement as below but want to add a date
> > parameter, where in the statement do I add it ?? can anyone help - I keep
> > trying different places but it returns errors - Thank You
> >
> > SELECT Count([Main Audit Data].[Boiler Type]) AS [Number of faults], [Main
> > Audit Data].[Boiler Type], [Main Audit Data].Status
> > FROM [Main Audit Data]
> > WHERE ((([Main Audit Data].[Boiler Type]) Like "*isar*")) AND ([Main Audit
> > Data].Status="warranty")
> > GROUP BY [Main Audit Data].[Boiler Type], [Main Audit Data].Status;
> >
> > Include this date parameter where ?????
> > HAVING ((([Main Audit Data].[Audit Date]) Between #1/1/2008# And
> > #31/01/2008#))

>

 
Reply With Quote
 
blake7
Guest
Posts: n/a
 
      30th Oct 2008
Just one more question John, when you say enter the dates in yyyy-mm-dd
format or the US style, do you mean in the design view or SQL view of the
query ?
Thanks

"John Spencer" wrote:

> Include that as part of the where clause.
>
> SELECT Count([Main Audit Data].[Boiler Type]) AS [Number of faults]
> , [Main Audit Data].[Boiler Type]
> , [Main Audit Data].Status
> FROM [Main Audit Data]
> WHERE [Main Audit Data].[Boiler Type] Like "*isar*"
> AND [Main Audit Data].Status="warranty"
> AND [Main Audit Data].[Audit Date] Between #1/1/2008# And
> #31/01/2008#
> GROUP BY [Main Audit Data].[Boiler Type]
> , [Main Audit Data].Status;
>
> By the way, I would enter the dates in yyyy-mm-dd format or in the US format
> of mm/dd/yyyy.
>
> See the following for an explanation of why.
> International Dates in Access at:
> http://allenbrowne.com/ser-36.html
>
> John Spencer
> Access MVP 2002-2005, 2007-2008
> The Hilltop Institute
> University of Maryland Baltimore County
>
> blake7 wrote:
> > Hi all, I have the following SELECT statement as below but want to add a date
> > parameter, where in the statement do I add it ?? can anyone help - I keep
> > trying different places but it returns errors - Thank You
> >
> > SELECT Count([Main Audit Data].[Boiler Type]) AS [Number of faults], [Main
> > Audit Data].[Boiler Type], [Main Audit Data].Status
> > FROM [Main Audit Data]
> > WHERE ((([Main Audit Data].[Boiler Type]) Like "*isar*")) AND ([Main Audit
> > Data].Status="warranty")
> > GROUP BY [Main Audit Data].[Boiler Type], [Main Audit Data].Status;
> >
> > Include this date parameter where ?????
> > HAVING ((([Main Audit Data].[Audit Date]) Between #1/1/2008# And
> > #31/01/2008#))

>

 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      30th Oct 2008
Definitely use yyyy-mm-dd in the SQL view. If you enter a date in the grid
in the design view, I believe Access will interpret it correctly, but it
won't in the SQL view.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"blake7" <(E-Mail Removed)> wrote in message
news:69EE23FE-3565-445C-B2D0-(E-Mail Removed)...
> Just one more question John, when you say enter the dates in yyyy-mm-dd
> format or the US style, do you mean in the design view or SQL view of the
> query ?
> Thanks
>
> "John Spencer" wrote:
>
>> Include that as part of the where clause.
>>
>> SELECT Count([Main Audit Data].[Boiler Type]) AS [Number of faults]
>> , [Main Audit Data].[Boiler Type]
>> , [Main Audit Data].Status
>> FROM [Main Audit Data]
>> WHERE [Main Audit Data].[Boiler Type] Like "*isar*"
>> AND [Main Audit Data].Status="warranty"
>> AND [Main Audit Data].[Audit Date] Between #1/1/2008# And
>> #31/01/2008#
>> GROUP BY [Main Audit Data].[Boiler Type]
>> , [Main Audit Data].Status;
>>
>> By the way, I would enter the dates in yyyy-mm-dd format or in the US
>> format
>> of mm/dd/yyyy.
>>
>> See the following for an explanation of why.
>> International Dates in Access at:
>> http://allenbrowne.com/ser-36.html
>>
>> John Spencer
>> Access MVP 2002-2005, 2007-2008
>> The Hilltop Institute
>> University of Maryland Baltimore County
>>
>> blake7 wrote:
>> > Hi all, I have the following SELECT statement as below but want to add
>> > a date
>> > parameter, where in the statement do I add it ?? can anyone help - I
>> > keep
>> > trying different places but it returns errors - Thank You
>> >
>> > SELECT Count([Main Audit Data].[Boiler Type]) AS [Number of faults],
>> > [Main
>> > Audit Data].[Boiler Type], [Main Audit Data].Status
>> > FROM [Main Audit Data]
>> > WHERE ((([Main Audit Data].[Boiler Type]) Like "*isar*")) AND ([Main
>> > Audit
>> > Data].Status="warranty")
>> > GROUP BY [Main Audit Data].[Boiler Type], [Main Audit Data].Status;
>> >
>> > Include this date parameter where ?????
>> > HAVING ((([Main Audit Data].[Audit Date]) Between #1/1/2008# And
>> > #31/01/2008#))

>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding Date Range to Averageif statement lwilliams Microsoft Excel Misc 2 3rd Oct 2008 02:59 PM
Re: Adding date to parameter W.G. Ryan [MVP] Microsoft ADO .NET 2 25th Jan 2007 05:59 PM
Re: Adding date to parameter William \(Bill\) Vaughn Microsoft ADO .NET 0 24th Jan 2007 04:16 PM
Re: Help with Output Parameter Statement William \(Bill\) Vaughn Microsoft ADO .NET 3 31st Aug 2006 06:00 PM
Parameter Query with Parameter in If Statement Randal Microsoft Access Queries 2 15th Jul 2004 09:39 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:53 AM.