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
 group by?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

musclebreast
Yak Posting Veteran

70 Posts

Posted - 05/16/2013 :  17:22:12  Show Profile  Reply with Quote
Hi,

I've got the following Table:




 dataid   Name   Vernum   valstr  
 5088726   cvp.docx   2   Internal  
 5088726   cvp.docx   3   Personal  
 5088726   cvp.docx   1   Strictly Confidential  





I want as result one row. I need the value of column valstr where the value of the column is the highest.

I my example the result must be personal.

How Can I do it?

I tried to work with group by but it's not correct...i hope you will have a hint for me....

Bustaz Kool
Flowing Fount of Yak Knowledge

USA
1673 Posts

Posted - 05/16/2013 :  17:47:05  Show Profile  Reply with Quote
Look at the PIVOT operator. BOL has details.

=================================================
I am not one of those who in expressing opinions confine themselves to facts. (Mark Twain)
Go to Top of Page

musclebreast
Yak Posting Veteran

70 Posts

Posted - 05/16/2013 :  19:08:01  Show Profile  Reply with Quote
Hi,

thanks for your help...I know pivot from excel..but i can't see how to work with it in my case..i checked some sql samples and I can use table entries as headers...but, it is not whar I want...is there not another way or do I miss something?

Kinf regards,

Lara
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 05/16/2013 :  23:58:52  Show Profile  Reply with Quote

SELECT dataid,   Name,   Vernum,   valstr  
FROM
(
SELECT *,ROW_NUMBER() OVER (PARTITION BY dataid ORDER BY Vernum DESC) AS rn
FROM YourTable
)t
WHERE rn=1


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
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.07 seconds. Powered By: Snitz Forums 2000