Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | 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)
 Join Question
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

murrayb3024
Yak Posting Veteran

79 Posts

Posted - 06/19/2013 :  11:26:40  Show Profile  Reply with Quote
I am having a complete brain fart on this one. I have 2 tables and there is an ID to link them. One of the fields in table B is a calculated value. Table B is also an archive table so data just gets appended to it and there is a CalculatedDate. I was thinking I would use Max function on calculated date but then I found out that a person's calculated value may not be done each month.

Example

TableA
ID
1
2
3


TableB
ID CalcValue CalcDate
1 1234 4/30/2013
1 1211 5/31/2013
2 9999 5/31/2013
3 7777 3/31/2013
3 6666 4/30/2013


So for my results I would want:

ID CalcValue
1 1211
2 9999
3 6666

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 06/19/2013 :  11:31:38  Show Profile  Reply with Quote

SELECT ID,CalcValue
FROM 
(
SELECT ROW_NUMBER() OVER (PARTITION BY ID ORDER BY CalcDate DESC) AS Seq, * 
FROM TableB
)t
WHERE Seq=1


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

murrayb3024
Yak Posting Veteran

79 Posts

Posted - 06/19/2013 :  12:34:14  Show Profile  Reply with Quote
Thank you for the help
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 06/20/2013 :  01:02:26  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next 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