Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL Select with DateTime and Int
Message
From
14/06/2019 12:27:21
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
01669054
Message ID:
01669091
Views:
42
>Note that in SQL Server the field type is DateTime and in VFP it is Date.
>
>Here is the exact version of filter expression that I use in the SQL Select (note that the AND in the begging of the expression is because there are other filter expressions):
>
>
>dPassDate = date()  && but could be a different date since user can change it from the current date to a future date
>IF plSqlServer
>	cLifeExpFilter = " AND (PURCHASED IS NOT NULL AND LIFE_EXP IS NOT NULL AND LIFE_EXP > 0 AND ('" + 
>DTOS(dPassDate) + "' >= DATEADD( year, LIFE_EXP, PURCHASED)) ) "
>ELSE
>        *-- VFP DB
>	cLifeExpFilter = " AND (!EMPTY(PURCHASED) AND LIFE_EXP > 0 AND '" + DTOS(dPassDate) + "' >= 
>DTOS(GOMONTH(PURCHASED,LIFE_EXP*12)))"
>ENDIF 
>
Then it is better, you don't need to cast (actually did the casting to remove time portion). Looks like you are using ADO (if not easier to write for ODBC):
IF plSqlServer
	cLifeExpFilter = " AND (PURCHASED IS NOT NULL AND LIFE_EXP IS NOT NULL AND LIFE_EXP > 0 AND ( " +;
                                 " ? >= DATEADD( year, LIFE_EXP, PURCHASED)) ) "
ELSE
        *-- VFP DB
	cLifeExpFilter = " AND (!EMPTY(PURCHASED) AND LIFE_EXP > 0 AND ?  >= GOMONTH(PURCHASED,LIFE_EXP*12))"
ENDIF 

dPassDate = date()  && but could be a different date since user can change it from the current date to a future date
* add m.dPassDate to parameters
Ç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