Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Year function in date range not working
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01512452
Message ID:
01512454
Views:
56
Hi Cecil,

If you want to make your code portable to SQL Server, then I suggest to use IN (..) instead of VFP INLIST
and also avoid using functions as possible (unless you have an index on Year(ptd)) If you don't have such index, then it will be better to use
ptd between {1997-01-01} and {2009-12-31} -- assuming ptd is a date field and not datetime.

>I don't know why but I am getting dates (years) that are outside of the bounds of my SQL statement shown below. Why is the YEAR function not working? Neither statement below works within the date range I wanted.
>
>
>SELECT ;
>		 " " AS CheckOff, a.grpid, a.grpnum, b.lastname, b.firstname, b.dob, a.Hist, a.PlanKey, a.Status, a. Renewal, ;
>		a.ptd ;
>	FROM grpextcv  a ;
>	JOIN grpextin b ON a.grpid+a.grpnum=b.grpid+b.grpnum ;
>	WHERE a.Hist="99" AND ;
>		SUBSTR(DTOC(a.ptd), 7, 4) >= "1997" AND SUBSTR(DTOC(a.ptd), 7, 4) <= "2009" AND INLIST(a.Status, "A, B") ;
>		ORDER BY a.grpid, a.grpnum ;
>	INTO CURSOR tmpActiveBefore2009
>
>SELECT ;
>		 " " AS CheckOff, a.grpid, a.grpnum, b.lastname, b.firstname, b.dob, a.Hist, a.PlanKey, a.Status, a. Renewal, ;
>		a.ptd ;
>	FROM grpextcv  a ;
>	JOIN grpextin b ON a.grpid+a.grpnum=b.grpid+b.grpnum ;
>	WHERE a.Hist="99" AND ;
>		BETWEEN(YEAR(a.ptd), 1997, 2009) AND INLIST(a.Status, "A, B") ;
>		ORDER BY a.grpid, a.grpnum ;
>	INTO CURSOR tmpActiveBefore2009
>
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform