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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 View must have most recent date
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Karmashock
Starting Member

4 Posts

Posted - 06/13/2013 :  14:24:06  Show Profile  Reply with Quote
I need to compare two tables.

One table has customer information and another has a log of all service done for those customers. In the log is a date of WHEN the service was done.

What I need to do is create a view that filters the log so it only shows most recent service.

OR

Ideally, I'd love to have that most recent date in the log added as a field along with information from the customer table.


The issue is that we're integrating two databases. Our database has a "done last" variable for every customer. The data we're adding has no such variable. What we have is the full schedule.




I am an SQL newbie. I really know very little about its syntax. But if you throw some code at me, I'll probably figure it out pretty quickly.


Anyone have any ideas or am I posting this in the wrong place?

djj55
Constraint Violating Yak Guru

USA
283 Posts

Posted - 06/13/2013 :  14:37:29  Show Profile  Reply with Quote
First are the two databases on the same instance of SQL? Or do you mean you have two SQL servers?

djj
Go to Top of Page

MIK_2008
Flowing Fount of Yak Knowledge

Pakistan
1050 Posts

Posted - 06/13/2013 :  14:44:24  Show Profile  Reply with Quote
Considering the log table is named: CustomerServiceLog
SELECT * FROM (
SELECT CustomerServiceLogID --Primary/Unique Key
,CustomerID
,LogDate
,Row_Number() Over (Partition By Customer_ID Order by LogDate Desc) MostRecentLogSequence
FROM CustomerServiceLog
)A
WHERE MostRecentLogSequence=1

Cheers
MIK
Go to Top of Page

Karmashock
Starting Member

4 Posts

Posted - 06/14/2013 :  01:16:02  Show Profile  Reply with Quote
quote:
Originally posted by MIK_2008

Considering the log table is named: CustomerServiceLog
SELECT * FROM (
SELECT CustomerServiceLogID --Primary/Unique Key
,CustomerID
,LogDate
,Row_Number() Over (Partition By Customer_ID Order by LogDate Desc) MostRecentLogSequence
FROM CustomerServiceLog
)A
WHERE MostRecentLogSequence=1

Cheers
MIK



Thanks. This did the trick. You're the man.
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.06 seconds. Powered By: Snitz Forums 2000