Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
murrayb3024
Yak Posting Veteran
79 Posts |
Posted - 2013-06-19 : 11:26:40
|
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.ExampleTableAID 123TableBID CalcValue CalcDate1 1234 4/30/20131 1211 5/31/20132 9999 5/31/20133 7777 3/31/20133 6666 4/30/2013So for my results I would want:ID CalcValue1 12112 99993 6666 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-06-19 : 11:31:38
|
[code]SELECT ID,CalcValueFROM (SELECT ROW_NUMBER() OVER (PARTITION BY ID ORDER BY CalcDate DESC) AS Seq, * FROM TableB)tWHERE Seq=1[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
murrayb3024
Yak Posting Veteran
79 Posts |
Posted - 2013-06-19 : 12:34:14
|
Thank you for the help |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-06-20 : 01:02:26
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|