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

  • SEARCH
  • Home
  • 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 6146407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:56:34+00:00 2026-05-23T18:56:34+00:00

I have files that are versioned, using a major and minor version. Now what

  • 0

I have files that are versioned, using a major and minor version.
Now what I want to do is grab the highest major versions of all the files (which I’ve done already). Then check minor versions to see if it contains a 0. If it does throw out that whole set of versions. So for instance. My first query returns:

FileA Ver 1.0, 1.1, 1.2, 1.3 
FileB Ver 2.1, 2.2, 2.3, 2.4 
FileC Ver 5.1, 5.2, 5.3. 

So in all 11 rows/records. Now my second query should take that result and throw out all of the FileA versions because one of the versions has a 0 as a minor version. So the second query should return:

FileB Ver 2.1, 2.2, 2.3, 2.4 
FileC Ver 5.1, 5.2, 5.3. 

7 rows/records in all.
Could anyone help me with this query? I’m using SQL server 2008 if that helps.

latestFileMajorVersion(fileId, majRev)
as
(
    --Gets files with highest major version
    select distinct v_fileid, max(v_majrev)
    from files
    group by v_fileid
),
latestFileVersions(fileId, majRev, minRev)
as
(
    --Gets files with highest major version and all minor versions
    select fileId, majRev, minrev
    from files
    inner join latestFileMajorVersion on files.v_fileid = latestFileMajorVersion.fileId
    where v_majrev = latestFileMajorVersion.majRev
),
latestFileVersion(fileId, majRev, minRev)
as
(
    select fileId, majRev, minrev
    from latestFileVersions
    where --I'm stuck here.
)
select v_fileid, v_majrev, v_minrev, v_status
from files
inner join latestFileVersion on v_fileid = latestFileVersion.fileId
where latestFileVersion.majRev = v_majrev and latestFileVersion.minRev = v_minrev and v_status = 'UnAssigned'

The table:

CREATE TABLE [dbo].[Files](
    [v_fileid] [uniqueidentifier] NOT NULL,
    [v_libid] [uniqueidentifier] NOT NULL,
    [v_userid] [uniqueidentifier] NOT NULL,
    [v_majrev] [int] NOT NULL,
    [v_minrev] [int] NOT NULL,
    [v_status] [nvarchar](16) NOT NULL,
 CONSTRAINT [PK_Files] PRIMARY KEY CLUSTERED 
(
    [v_fileid] ASC,
    [v_majrev] ASC,
    [v_minrev] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY],
 CONSTRAINT [IX_Files] UNIQUE NONCLUSTERED 
(
    [v_majrev] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY],
 CONSTRAINT [IX_Files] UNIQUE NONCLUSTERED 
(
    [v_minrev] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
  • 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-05-23T18:56:35+00:00Added an answer on May 23, 2026 at 6:56 pm

    Here’s a working solution with a little example table you can play with. Execute it exactly as it is with no other sql around it. You can then modify it to suit your need.

    declare @files table (fileId int identity(1,1), majRev int, minRev int)
    insert into @files values (1,0)
    insert into @files values (1,1)
    insert into @files values (2,0)
    insert into @files values (2,2)
    insert into @files values (3,1)
    insert into @files values (3,2)
    insert into @files values (4,1)
    
     select fileId, majRev, minRev
       from @files f
      where not exists 
            (select *
               from @files
              where minRev = 0
                and majRev = f.majRev
                and fileId = f.fileId)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML file that contains a version number (major.minor.build) element and I'd
I have 2 wav files that I want to concatenate into one file with
I only want a list of files that have been added (not ones that
Is there any way to list all the files that have changed between two
Using Installshield 2010 with a Basic MSI project. I have several config files that
I want to know the list of files that are known to version control.
I have a XML File like that <?xml version=1.0 encoding=utf-8 ?> <Configurations> <EmailConfiguration> <userName>xxxx</userName>
I have several files that are in several different languages. I thought they were
I have some source files that have comments written in Japanese. When I open
I have two PHP files that I need to link. How can I link

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.