0
Participant
,
/t5/coldfusion-discussions/querying-dates-by-quarter/td-p/550972
Apr 25, 2007
Apr 25, 2007
Copy link to clipboard
Copied
Greetings all!
After doing a bit of research I've written a query to return a list of results based on the Quarter. I got passed any errors but the query now returns zero results on all 4 Quarters. Not sure what I'm missing here. The field in the database is set to Date/Time. Any help would be greatly appreciated, David.
After doing a bit of research I've written a query to return a list of results based on the Quarter. I got passed any errors but the query now returns zero results on all 4 Quarters. Not sure what I'm missing here. The field in the database is set to Date/Time. Any help would be greatly appreciated, David.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
1 Correct answer
Mentor
,
Apr 25, 2007
Apr 25, 2007
Remove the single quotes. DatePart("q",LdSaledate) is a
function call, and #Quarter# is numeric.
Phil
Phil
Mentor
,
/t5/coldfusion-discussions/querying-dates-by-quarter/m-p/550973#M50542
Apr 25, 2007
Apr 25, 2007
Copy link to clipboard
Copied
What database are you using. Since
DatePart("q",LdSaledate) is enclosed within single quotes in
the statement 'DatePart("q",LdSaledate)' = '#Quarter#', it is being
treated as string not a database function call. The database type
will determine what actual date/time functions are available to
use.
Phil
Phil
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Inkfast
AUTHOR
Participant
,
/t5/coldfusion-discussions/querying-dates-by-quarter/m-p/550974#M50543
Apr 25, 2007
Apr 25, 2007
Copy link to clipboard
Copied
The DB is Access. I took the code from an Access dev site and
wrote it in that way so when CF wrote the SQL statement it would be
readable by Access. I thought it would work that way.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Mentor
,
/t5/coldfusion-discussions/querying-dates-by-quarter/m-p/550975#M50544
Apr 25, 2007
Apr 25, 2007
Copy link to clipboard
Copied
Remove the single quotes. DatePart("q",LdSaledate) is a
function call, and #Quarter# is numeric.
Phil
Phil
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Advocate
,
/t5/coldfusion-discussions/querying-dates-by-quarter/m-p/550976#M50545
Apr 25, 2007
Apr 25, 2007
Copy link to clipboard
Copied
EDIT - ah I see paross1 already posted this as I was typing
it.
Have you tried paross1's suggestion?
<cfquery datasource="Leads" name="GetLeads">
Select *
From Ld_Tbl
Where LdAgent = '#LdAgent#'
And DatePart("q",LdSaledate) = #Quarter#
</cfquery>
Just to confirm - are you only storing data for 1 year or do you need to know what year the quarter occured in?
Have you tried paross1's suggestion?
<cfquery datasource="Leads" name="GetLeads">
Select *
From Ld_Tbl
Where LdAgent = '#LdAgent#'
And DatePart("q",LdSaledate) = #Quarter#
</cfquery>
Just to confirm - are you only storing data for 1 year or do you need to know what year the quarter occured in?
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Inkfast
AUTHOR
Participant
,
/t5/coldfusion-discussions/querying-dates-by-quarter/m-p/550977#M50546
Apr 25, 2007
Apr 25, 2007
Copy link to clipboard
Copied
Phil's answer fixed it. The Leads will have been converted to
either Sale or Dead by the time the same quarter would roll around
in the next year so that won't be an issue. Just for the fun of it
what if I did want to query Q/YYYY?
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Advocate
,
/t5/coldfusion-discussions/querying-dates-by-quarter/m-p/550978#M50547
Apr 25, 2007
Apr 25, 2007
Copy link to clipboard
Copied
You may also want to try using <cfqueryparam>'s in your
query. Using #quarter# could open you up to SQL injection.
instead of
= #Quarter#
Try this:
= <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#Quarter#">
that should give you some protection and speed up your queries as well.
instead of
= #Quarter#
Try this:
= <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#Quarter#">
that should give you some protection and speed up your queries as well.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Inkfast
AUTHOR
Participant
,
LATEST
/t5/coldfusion-discussions/querying-dates-by-quarter/m-p/550979#M50548
Apr 25, 2007
Apr 25, 2007
Copy link to clipboard
Copied
Good idea!. I have really got to take the time for some
advanced classes. Thanks guys!!!
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

