Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9195055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:33:05+00:00 2026-06-17T21:33:05+00:00

Using SQL Server 2005, I am attempting to write a select statement which will

  • 0

Using SQL Server 2005, I am attempting to write a select statement which will query the data below (18000 rows) and return one row per Product, finding the largest product version.

I think the query needs to compare the versions in reverse, and storing the largest row number as it gets up to Major but I am not sure.

Sample Data

    Product  Date       Major  Minor  Release Fixpack Build
    =======  ========== ====== ====== ======  ======  ======
    Widgets  01/01/2012 10     1      0       345     132
    Widgets  04/02/2011 6      6      3       932     245
    Widgets  09/01/2010 4      92     345     53      2
    Gears    03/17/2011 9      2      3       0       21
    Gears    12/12/2012 10     0      0       5       548
    Tires    04/24/2000 8      3      456     3       984
    Tires    04/12/1993 7      14     45      35      252

Expected Results

    Product  Date       Major  Minor  Release Fixpack Build
    =======  ========== ====== ====== ======  ======  ======
    Widgets  01/01/2012 10     1      0       345     132
    Gears    12/12/2012 10     0      0       5       548
    Tires    04/24/2000 8      3      456     3       984

OR even better, could combine the versions into one column:

    Product  Date       ProductVersion
    =======  ========== ==================
    Widgets  01/01/2012 10.1.0.345.132
    Gears    12/12/2012 10.0.0.5.548
    Tires    04/24/2000 8.3.456.3.984
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:33:06+00:00Added an answer on June 17, 2026 at 9:33 pm

    You can use the ROW_NUMBER function in a derived table. Do the partition on Product and order by Date desc or your version information.

    Ordered by Date desc:

    select T.Product,
           T.Date,
           T.ProductVersion
    from (
         select Product,
                Date,
                cast(Major as varchar(5))+'.'+
                cast(Minor as varchar(5))+'.'+
                cast(Release as varchar(5))+'.'+
                cast(Fixpack as varchar(5))+'.'+
                cast(Build as varchar(5)) as ProductVersion,
                row_number() over(partition by Product order by Date desc) as rn
         from YourTable
         ) as T
    where T.rn = 1
    

    Ordered by ProductVersion desc

    select T.Product,
           T.Date,
           T.ProductVersion
    from (
         select Product,
                Date,
                cast(Major as varchar(5))+'.'+
                cast(Minor as varchar(5))+'.'+
                cast(Release as varchar(5))+'.'+
                cast(Fixpack as varchar(5))+'.'+
                cast(Build as varchar(5)) as ProductVersion,
                row_number() over(partition by Product 
                                  order by Major desc, 
                                           Minor desc, 
                                           Release desc, 
                                           Fixpack desc, 
                                           Build desc) as rn
         from YourTable
         ) as T
    where T.rn = 1
    

    SQL Fiddle

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using SQL Server 2005 how do I get the below statement or rather the
Using SQL Server 2005 I have a query that gets child records from bundles
I´m using SQL Server 2005 and Visual Studio 2008, C#. In the data source
Using SQL Server 2005, I am working with a database which has two columns
Using SQL Server 2005 and VB6 When I executing for yearly data or more
Using SQL Server 2005\2008 Is there a way to copy a particular data row
Using SQL Server 2005, I am trying to select a certain number of records
I am using SQL Server 2005 and I wanted to create MERGE statement or
I'm using SQL SERVER 2005 and have a table which stores challans datewise. It
I'm using SQL Server 2005. I have a query to a server that gives

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.