SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help on max date error
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

02119
Starting Member

8 Posts

Posted - 01/29/2013 :  11:20:07  Show Profile  Reply with Quote
here is my code

select *
from dbo.vw_ComplyWise_Last_ERD
join (select EMPLOYEE_ID,MAX(DATE_OBTAINED)As Date_Obtained
from dbo.vw_ComplyWise_Last_ERD
group by EMPLOYEE_ID)
using (EMPLOYEE_ID,DATE_OBTAINED)

but i get the following error
Msg 102, Level 15, State 1, Line 6
Incorrect syntax near ')'.

I'm trying to only return the last record based on the date obtained for each employee

Thanks i advance
Steve

russell
Pyro-ma-ni-yak

USA
5072 Posts

Posted - 01/29/2013 :  11:27:16  Show Profile  Visit russell's Homepage  Reply with Quote
select *
from dbo.vw_ComplyWise_Last_ERD
join (select EMPLOYEE_ID,MAX(DATE_OBTAINED)As Date_Obtained
from dbo.vw_ComplyWise_Last_ERD
group by EMPLOYEE_ID)
using (EMPLOYEE_ID,DATE_OBTAINED)

what is that? that's not valid SQL Server syntax
and you should specify what you're joining on.

Edited by - russell on 01/29/2013 11:28:08
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 01/29/2013 :  11:34:26  Show Profile  Reply with Quote

select t.*
from dbo.vw_ComplyWise_Last_ERD t
join (select EMPLOYEE_ID,MAX(DATE_OBTAINED)As Date_Obtained
from dbo.vw_ComplyWise_Last_ERD
group by EMPLOYEE_ID)m
ON m.EMPLOYEE_ID = t.EMPLOYEE_ID 
AND m.DATE_OBTAINED = t.DATE_OBTAINED 


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

02119
Starting Member

8 Posts

Posted - 01/29/2013 :  11:53:22  Show Profile  Reply with Quote
Thanks that worked perfectly.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 01/29/2013 :  12:48:56  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.2 seconds. Powered By: Snitz Forums 2000