On Wed, May 11, 2011 at 1:07 PM, Rafael Copquin <[email protected]> wrote:
> What is the transact sql equivalent of the date() function?
>
> How would you change the following vfp statement into a transact sql
> statement?
>
> select * from invoices where invdate = date()

There's not a one-to-one mapping, and there are a couple different
ways to do it, depending on the circumstances. Dates are easily
ambiguous, so you have to use caution, especially if users may have
different localization settings. My recommendation is to used named
parameters:

ldDate = DATE()
lcSQL = "SELECT * FROM invoices WHERE invdate = ?ldDate"
lnResult = SQLEXEC(lnHandle, lcSQL)

Alternatively, you can convert the date to a string using the
ODBC-escaped date format:

lcDate = "{d YYYY-MM-DD}" && convert the date as best suits you
lcSQL = "SELECT * FROM invoices WHERE invdate = " + lcDate

-- 
Ted Roche
Ted Roche & Associates, LLC
http://www.tedroche.com

_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/[email protected]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to