Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Access data base datetime query - what datetime format??
Message
From
25/07/2003 05:04:35
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00813055
Message ID:
00813421
Views:
8
>>>I am doing ODBC queries on an Access database. Everything works but I don't know how to format my dates in my VFP code in the SQL query. If I want to get all records where indate > mydate (where indate is an Access datetime field and mydate is a my var in the SQL) how do I format mydate? I tried dtoc() and ttoc() with and without the ,1 parameter but no luck.
>>>
>>>TIA
>>>John.
>>
>>where indate > ?mydate
>>Cetin
>
>Cetin,
>thanks a million, that's what I needed. One more question. Do you know of any place where I can find some helpful hints on running SQLs on Access tables from VFP? I'm new at this but I have to now interface my VFP program with another that is in Access. If I could just find a bunch of examples I would be in great shape. The ODBC is working just fine. I just need some SQL examples.
>
>John.

John,
First I didn't include #dateliteral# format. It can be used but Access waits the dateliteral be in either US format or YYYY/MM/DD format. I find it restricting and not reliable. Second, using that style your SQL is limited to Access. OTOH ? parametric passing is recognized by not only access but by other backends like SQL server, Oracle etc.
If you want to use it you might construct your query like :
ldStart = {^1996/07/01}
ldEnd = {^1996/07/31}

lcSQL = "select * from [Orders] where [RequiredDate] between #"+;
  Transform(Dtoc(ldStart,1), '@R 9999/99/99')+"# and #"+;
  Transform(Dtoc(ldEnd,1), '@R 9999/99/99')+"#"	
However it would get quickly tedious as field count increases.
lcSQL = "select * from [Orders] where [RequiredDate]"+;
 " between ?ldStart and ?ldEnd"
Is more compact and understandable IMHO.

I don't know a place that have samples. But I think you also don't need the samples :) Any SQL you know in VFP (provided you don't use VFP specific formats and functions) would work. ie:

Most backends do not understand :

between(indate,?ldStart,?ldEnd)

But they all understand :

indate between ?ldStart and ?ldEnd

Some VFP functions are also recognized by other backends. ie: In access date(1996,10,1) is same as in VFP, left(), right() exists in many backends etc. You would need to check Access help for its supported functions (but I'd stick with globally known ways of defining a query as much as I can).

One note that might be helpfull for Access, surround your table, fieldnames with brackets ([]). Access table and field names can contain spaces and start with a digit. Brackets let you correctly point to a table, fieldname. ie:

select * from [my Access Table] where [my Access Table].[my field] like 'A%'

Other than that using ? parameterizing your SQL statements for insert, update, select, delete etc should be easy.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform