Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

date add in query issue 1

Status
Not open for further replies.

alsjka

Technical User
Jan 21, 2003
114
0
0
US
I want to be able to return all records that are greater than 4 weeks from the date received. I want to use the following query is this possible?


select ponum, count(itemnum) as itemnum, count(invoicenum) as invoicenum
from poreceiv
where ponum = '#get_po_item.ponum#'
and itemnum = '#get_po_item.item#'
and datereceived > #dateadd("ww", -4, datereceived)#
 
Code:
select ponum, count(itemnum) as itemnum, count(invoicenum) as invoicenum
from poreceiv
where ponum = '#get_po_item.ponum#'
and itemnum = '#get_po_item.item#'
and datereceived LT #(NOW()-28)#

I'm away from my environment at the moment but i think that will return all results that have not be recieved in the last 28 days, so are more than 28 days old.

I'm probably wrong, but thought i'd give it a shot.

Rob
 
Just add createodbcdate() to your code and it's perfect:

Code:
select ponum, count(itemnum) as itemnum, count(invoicenum) as invoicenum
from poreceiv
where ponum = '#get_po_item.ponum#'
and itemnum = '#get_po_item.item#'
and datereceived > #[b][COLOR=red]createodbcdate([/color][/b]dateadd("ww", -4, datereceived)[b][COLOR=red])[/color][/b]#
 
My code above assumes you have a local variable called #datereceived# that you are comparing the database field against. I think what you actually want is this:

Code:
select ponum, count(itemnum) as itemnum, count(invoicenum) as invoicenum
from poreceiv
where ponum = '#get_po_item.ponum#'
and itemnum = '#get_po_item.item#'
and datereceived < #createodbcdate(dateadd("ww", -4, now()))#
 
just use cfqueryparam, it will format your dates correctly for your database. You should use cfqueryparam on all of your CF variables in your query.

select ponum, count(itemnum) as itemnum, count(invoicenum) as invoicenum
from poreceiv
where ponum = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#get_po_item.ponum#">
and itemnum = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#get_po_item.item#">
and datereceived < <cfqueryparam cfsqltype="CF_SQL_DATE" value="#dateadd("ww", -4, now())#">

Kevin
 
Thanks all great reply's!

I will try this when at work tomorrow.

JKA!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top