Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Usability of date syntax in SQL
Message
From
10/04/2003 05:48:55
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
10/04/2003 00:50:49
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00775883
Message ID:
00775926
Views:
16
>On some occasions, I have the need to incorporate in my SQL the value of the numeric field as is. For example, if I have a lnYear value of 1999 and that I am building a lcSQL string, I would do as is:
>
>
>lcSQL='SELECT Numero FROM News WHERE Year='+ALLTRIM(STR(lnYear))
>&lcSQL
>
>
>So, this allows me to pass lcSQL as a parameter and have it working in another method. Otherwise, if I would do:
>
>
>lcSQL='SELECT Numero FROM News WHERE Year=lnYear
>&lcSQL
>
>
>I would need to have lnYear visible in the method.
>
>My question is how can I achieve the same with a date? I want to be optimizable and if I use:
>
>
>lcSQL='SELECT Numero FROM News WHERE StartDate=CTOD('01/01/1999')
>&lcSQL
>
>
>This won't be.
lcSQL = 'SELECT Numero FROM News WHERE StartDate = {^'+;
 TRANSFORM(DTOC(ldDate,1),'@R 9999/99/99')+'}'
But these conversions might get tedious to use. Instead I'd put parameters to a custom object and pass it as well. ie:
LOCAL oParams, lcSQL
oParams = CREATEOBJECT('Custom')
oParams.AddProperty('p_StartDate', {^1999/01/01})
oParams.AddProperty('p_EndDate', {^1999/10/22})
oParams.AddProperty('p_Title', 'VFP')

lcSQL = '* FROM News'+;
' WHERE StartDate = toParams.p_StartDate'+;
'    and EndDate = toParams.p_EndDate'+;
'    and atc(toParams.p_Title,Title) > 0'
RunSQL(lcSQL, oParams, 'myCursor')


FUNCTION RunSQL
LPARAMETERS tcSQL, toParams, tcOutCursor
Select &tcSQL into cursor (tcOutCursor)
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