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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:11:18+00:00 2026-06-07T06:11:18+00:00

I have a Question table with the fields (QuestionID,QuestionMarks), and with the data fields

  • 0

I have a Question table with the fields (QuestionID,QuestionMarks), and with the data fields look like –

 QuestionID   QuestionMarks
   1              1
   2              4
   5              1
   9              1
   12             2

which means at the moment Question table has 5 Question of Total 9 marks, Now my problem is that i want to know that a combination of 4 Questions with 8 marks is possible and fetch out that combination ( in general a combination of “x” questions of “y” marks is possible) ?

I was thinking to use CTE, but was afraid that it will take lot of time to execute the query if i have tens of thousand question.

please suggest some idea how to get the data. I am using SQL Server version 2008

  • 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-07T06:11:19+00:00Added an answer on June 7, 2026 at 6:11 am

    This is a start. It’s going to have poor performance:

    declare @Qs table (QuestionID int not null, QuestionMarks int not null)
    insert into @Qs (QuestionID,QuestionMarks) values
    (1,1), (2,4), (5,1), (9,1), (12,2)
    
    declare @TargetMarks int = 8
    declare @TargetCount int = 4
    
    ;with Build as (
        select QuestionID as MinID,QuestionID as MaxID,QuestionMarks as Total,1 as Cnt
            ,'/' + CONVERT(varchar(max),QuestionID) + '/' as QPath
        from @Qs
        union all
        select MinID,q.QuestionID,Total+q.QuestionMarks,Cnt+1,QPath + CONVERT(varchar(max),q.QuestionID) + '/'
        from
            Build b
                inner join
            @Qs q
                on
                    b.MaxID < q.QuestionID and
                    b.Total + q.QuestionMarks <= @TargetMarks and
                    b.Cnt < @TargetCount
    )
    select * from Build where Cnt = @TargetCount and Total = @TargetMarks
    

    Result set:

    MinID       MaxID      Total       Cnt         QPath
    --------------------------------------------------------------------------------
    2           12          8           4           /2/5/9/12/
    1           12          8           4           /1/2/9/12/
    1           12          8           4           /1/2/5/12/
    

    The tricky part is that the QPath value isn’t exactly the greatest way of storing ID values.

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

Sidebar

Related Questions

I have a table like this, with three fields: User | Question# | Answer
The question was, if you have an index on some fields in your table,
Just a small question regarding joins. I have a table with around 30 fields
I have the following setup: Table: Question QuestionId Table: QuestionTag QuestionId TagId Table: Tag
My database has two tables, question and field. Questions may have many fields, and
I have a question related to query . I have a table in which
I have Question and QuestionTypes. In Question table there is a foreign key that
I just saw this dating site on builtwithbootstrap and have a question about table
I have a question regarding the table structure of my settings table. I've taken
i have a question how to select certain values from a table. I have

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.