Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
What's wrong with this SPT containing dates
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 8 SP1
Database:
MS SQL Server
Miscellaneous
Thread ID:
01134926
Message ID:
01134943
Views:
14
>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.
Previous
Reply
Map
View

Click here to load this message in the networking platform