Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Usability of date syntax in SQL
Message
De
10/04/2003 05:48:55
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
10/04/2003 00:50:49
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00775883
Message ID:
00775926
Vues:
15
>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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform