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 |
tirby
Starting Member
3 Posts |
Posted - 2009-04-13 : 14:10:21
|
What happens when you give a geologist a computer? You get a geologist asking stupid questions.I’m off shore right now so I can’t run and get a book, so bare with me.I am working with sql server 2005 on a remote connection. I can connect to and pull data. So I have a good connection and no security problems. I have a very simple table consisting of 3 fieldsField 1 well_nameField 2 dateField3 water_producedExample tableWell1 01/01/2009 25 Well1 02/01/2009 35Well2 01/01/2009 20 Well2 02/01/2009 21 I need to create a view that shows the latest record per well nameExampleWell1 02/01/2009 35Well2 02/01/2009 21That is the last record based on the dateI am using Microsoft SQL Server Management Studio Express to make the view |
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-04-13 : 14:14:53
|
Try this query to create the view.select a.well_name,a.date,a.water_producedfrom (select well_name,date,water_produced,row_number() over(partition by well_name order by date desc) as seq from <urtable> ) awhere a.seq = 1 |
 |
|
tirby
Starting Member
3 Posts |
Posted - 2009-04-13 : 16:22:44
|
Worked great didnt know i could nest the statements like that thanks |
 |
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-04-13 : 16:30:11
|
welcome |
 |
|
|
|
|