Advertisement

08.06.2008 at 11:36AM PDT, ID: 23626781
[x]
Attachment Details

Query, no cursors .. is it possible?

[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.8
Tags:

Microsoft, SQL server, 2005

I will try to explain my requirement by giving this following sample of data. Consider the following table
declare @test table (id  varchar(10), score  int)

with these records

insert into @test values('A', 10)
insert into @test values('B', 20)
insert into @test values('C', 40)
insert into @test values('D', 8)
insert into @test values('E', 30)
insert into @test values('F', 2)
insert into @test values('G', 15)
insert into @test values('H', 10)
insert into @test values('I', 15)

Now I want to write a query (I know how to do the same using cursors) which will group the above records (sum(score)  <=40) and also rank it .. basically the rank is just a unique number given to each group <=40 .. so the result would look something like this ...
id, score, rank
'A', 10, 1
'B', 20, 1
'C', 40, 2    --> another rank because adding this scrore (40) to to rank 1 (sum = 30) will go above 40
'D', 8, 3     --> another rank because adding this scrore (3) to to rank 2 (sum = 40) will go above 40
'E', 30, 3
'F', 2, 3
'G', 15, 4   --> another rank because adding this scrore (15) to to rank 3 (sum = 32) will go above 40
'H', 10, 4
'I', 15, 4

I hope you get it .. please feel to ask questions if its not very clear ..

For the more curious ones who need to know why I have such a requirement ...
I have a table which contains names of multipage TIFF images and each image can have more than 1 page. So the table would be something like this
Filename, pagecount
'A', 5
'B', 6
'C', 20 ..... just as the sample date given above

Now the requirement is that I need to extract these documents and create folders, each folder having not more than 2000 pages (NOT images, note each image can have more than one page). Also note that if adding the last image to a folder exceeds the count to > 2000, then the whole image needs to be moved. So in short, a image cannot be split between folders.

Thanks a lot in advance
Rejo
 
 
 
Expert Comment by angelIII:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Assisted Solution by chapmandew:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Expert Comment by ScottPletcher:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Expert Comment by chapmandew:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Expert Comment by angelIII:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Expert Comment by chapmandew:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Accepted Solution by angelIII:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Expert Comment by ScottPletcher:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Expert Comment by chapmandew:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Expert Comment by chapmandew:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Expert Comment by chapmandew:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Author Comment by Rejojohny:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Expert Comment by chapmandew:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Expert Comment by ScottPletcher:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Author Comment by Rejojohny:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Expert Comment by chapmandew:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Expert Comment by chapmandew:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
20081119-EE-VQP-46 / EE_QW_2_20070628