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 8933077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:27:09+00:00 2026-06-15T09:27:09+00:00

I have been stumped on this for quite awhile. Request#, SlotId, Segment, and Version

  • 0

I have been stumped on this for quite awhile. Request#, SlotId, Segment, and Version all make up the primary key. What i want from my stored proc is to be able to retrieve all rows by passing in the Request # and Segment, but for each slot i want the most recent effective date on or before todays date and from that i need the highest version #. I appriciate your time.

Values in database
Request#  SlotId  Segment Version Effective Date  ContentId
 A123       1       A       1         2012-01-01      1
 A123       2       A       1         2012-01-01      2 
 A123       2       A       2         2012-02-01      34
 A123       2       A       3         2012-02-01      24
 A123       2       A       4         2015-01-01      6 //beyond todays date. dont want

Values I want to return from my stored proc when i pass in A123 for Request # and A for Segment.

 A123       1       A       1         2012-01-01      1
 A123       2       A       3         2012-02-01      24
  • 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-15T09:27:11+00:00Added an answer on June 15, 2026 at 9:27 am

    The query could be written like this:

    ; WITH cte AS
        ( SELECT Request, SlotId, Segment, Version, [Effective Date], ContentId,
                 ROW_NUMBER() OVER ( PARTITION BY Request, Segment, SlotId
                                     ORDER BY Version DESC ) AS RowN
          FROM
                tableX
          WHERE
                Request = @Req  AND  Segment = @Seg             --- the 2 parameters
            AND [Effective Date] < DATEADD(day, 1, GETDATE())
        )
      SELECT Request, SlotId, Segment, Version, [Effective Date], ContentId
      FROM cte
      WHERE Rn = 1 ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been stumped all day on this problem. Basically I want to check
i have been stumped on this for quite a while now. I am trying
I have been stumped on this one for a while. I want to take
I have been very stumped by this one. I have a fairly large (~1500
I have been stumped for 3 hours now on this problem, I need to
Hey this might be a simple question, but i have been stumped on it
I have been stumped by this problem. I need to create a pattern such
I have been googling about this issue for hours, and I'm stumped. Im trying
I'm quite stumped on this issue. I have a large library of H.264 mp4
I've been stumped for bit on this one - I have a string that

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.