Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Selecting MAX Date
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP2
Network:
Windows 2008 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01531005
Message ID:
01531006
Views:
41
>I wrote a SQL statement that appeared to be okay, but it has an error:
>
>"SQL: column 'EFF_DATE' is not found".
>
>What did I do wrong? I am trying to not have dupe records. The only way to do that is to get the Maximum Effective Date.
>
>SELECT DISTINCT cv.GrpID, cv.GrpNum, in.Emp_ID, in.LastName, in.FirstName, in.SS_Number, ;
>		cv.Eff_Date;
>	FROM GRPEXTIN in ;
>	JOIN ;
>		(SELECT GrpID, GrpNum, MAX(Eff_Date) AS MaxEffDate FROM GRPEXTCV GROUP BY GrpID, GrpNum) cv ;
>		ON in.GrpID+in.GrpNum=cv.GrpID+cv.GrpNum  ;
>	WHERE cv.Hist ='99' AND ;
>		(INLIST(cv.GrpID, "ACS") AND ;
>		INLIST(cv.Status, 'A' ,'B') AND ;
>		cv.Renewal<>'H') ;
>	ORDER BY cv.GrpID, cv.GrpNum ;
>	INTO CURSOR tmpResults
>
You named your date as MaxEffDate, so this is the name you should use in your query. Also, I suggest to use join as
In1.GrpID = cv.GrpID and In1.GrpNum = cv.GrpNum

and use something like In1 instead of In for first table alias. Finally, instead of INLIST I suggest using IN to make the code more SQL like.
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