Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
What's wrong with this SPT containing dates
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 8 SP1
Database:
MS SQL Server
Divers
Thread ID:
01134926
Message ID:
01134943
Vues:
15
>Hi all
>
>Can anybody suggest what may be wrong in this SPT to MS-SQL. It just returns -1 for the SQLEXEC():
>
>StartDate = thisform.fromdate.value
>EndDate = thisform.todate.value
>
>TEXT TO cVar NOSHOW TEXTMERGE
>   SELECT CAST(RTRIM(charfield) AS char(10)) AS charfld,
>      <<m.StartDate>> AS StartDate, <<m.EndDate>> as EndDate
>   FROM myTable
>   LEFT JOIN ...
>   WHERE ...
>      AND fld_EntryDate >= <<m.StartDate>>
>      AND fld_EntryDate <= <<m.EndDate>>
>   ORDER BY ...
>ENDTEXT
>
>SQLEXEC(nHndl, cVar, "curname")
>
In addition to Sergey. Pass Date variables as Parameters and you will forget about coversions. Also if you didn't want to pass them as parameters you can p[ass them as strings with DTOS() format.

1. Pass dates as parameters
StartDate = thisform.fromdate.value
EndDate   = thisform.todate.value

TEXT TO cVar NOSHOW TEXTMERGE
   SELECT CAST(RTRIM(charfield) AS char(10)) AS charfld,
      ?m.StartDate AS StartDate, ?m.EndDate as EndDate
   FROM myTable
   LEFT JOIN ...
   WHERE ...
      AND fld_EntryDate >= ?m.StartDate
      AND fld_EntryDate <= ?m.EndDate
   ORDER BY ...
ENDTEXT
SQLEXEC(nHndl, cVar, "curname")
2. Pass dates as DTOS() string. SQL Server automaticly convert them to appripriate type
StartDate = DTOS(thisform.fromdate.value)
EndDate   = DTOS(thisform.todate.value)

TEXT TO cVar NOSHOW TEXTMERGE
   SELECT CAST(RTRIM(charfield) AS char(10)) AS charfld,
      CAST('<<m.StartDate>>' AS DateTime) AS StartDate,
      CAST('<<m.EndDate>>' AS DateTime) as EndDate
   FROM myTable
   LEFT JOIN ...
   WHERE ...
      AND fld_EntryDate >= '<<m.StartDate>>'
      AND fld_EntryDate <= '<<m.EndDate>>'
   ORDER BY ...
ENDTEXT
SQLEXEC(nHndl, cVar, "curname")
But in both cases you should check what SQLEXEC() returns and handle errors with AERROR().
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform