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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:18:53+00:00 2026-06-12T12:18:53+00:00

I have a SQL query for a table in which the user can create

  • 0

I have a SQL query for a table in which the user can create multiple ‘revisions’ of a form. Currently we pass in the ID of the revision into the query to retrieve the values (as you can probably guess), which is fine – however I want to extend to also select the previous revisions rows (if they is a previous revision). Each revision has a number which is incremented when they create a new revision. Here’s my query so far which doesn’t seem to run (obviously the value 1,value 2 are the actual columns in my query)

SELECT ID, SageJobID, SageJobPK, DateID, Revision, StatusID, Value1, Value2
FROM   CVRs
LEFT OUTER JOIN (SELECT TOP(1) * 
                  FROM CVRs AS prevCVR 
                  WHERE (prevCVR.DateID = CVRs.DateID 
                    AND prevCVR.SageJobPK = CVRs.SageJobPK 
                    AND prevCVR.ID <> CVRs.ID) 
                  ORDER BY prevCVR.Revision DESC) AS 'PrevCVR'
WHERE        (CVRs.ID = @ID)

It seems I can’t access the main CVR row I’m selecting from my join. Any ideas?

  • 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-12T12:18:54+00:00Added an answer on June 12, 2026 at 12:18 pm

    I made an SQL Fiddle with a simplified version to give you an idea how you can solve it. SQL Fiddle Demo here

    That would be then about this

    SELECT ID, SageJobID, SageJobPK, DateID, Revision, StatusID, Value1, Value2
    FROM   CVRs
    WHERE  DateId in    ( select dateid    from cvrs where CVRs.ID = @ID)
      and  sagejobpk in ( select sagejobpk from cvrs where CVRs.ID = @ID)
    order by revision desc
    

    Edit: I made another SQL Fiddle to also take the DateId aspect in but I got a question: Is it that all CV revisions that belong together must be of same DateId and SageJobPK?

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

Sidebar

Related Questions

I have a T-SQL query as below which queries a table holding the search
I have a query as follows: String SQL = insert into table (id, name)
I have sql stored procedure which pass and return some values: CREATE PROCEDURE [dbo].[GetMoney]
i have this sql query select * from table where name like ? but
i've a table like: i have to make sql query to get the average
I have a table of products, and I need to write an SQL query
need help/guide for sql select query, I have 2 table stock and stock_history, in
I have an image data type in my table. When I query using SQL
I'm currently looking at ways to pass lists of integers in a SQL query,
I have created a map which allows the user to plot multiple markers with

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.