SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Return multiple column results in same column.
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Chris_1
Starting Member

United Kingdom
3 Posts

Posted - 10/26/2011 :  12:18:52  Show Profile  Reply with Quote
Hi everyone,

I'm new here, so do excuse my newbieness. :)

I've been stumped with a SELECT query against an accounting database, with both closed and current accounts.

What I need to do is to return all accounts with the largest current account balance first, and then directly underneath, all former accounts that person has, in descending order. Then the next largest current account balance, and it's linked former accounts, then the next and so on.

I have been toying with the idea of using Rank and Union combined, but am unclear as to how effective this will actually be.

Any pointers you can give me would be greatly appreciated. :)

Chris.

Chris_1
Starting Member

United Kingdom
3 Posts

Posted - 10/26/2011 :  12:21:25  Show Profile  Reply with Quote
Edit: Former accounts in descending order of balance.
Go to Top of Page

Sachin.Nand
Flowing Fount of Yak Knowledge

2937 Posts

Posted - 10/26/2011 :  12:21:32  Show Profile  Reply with Quote
Not sure what you meant by "...directly underneath,all former accounts..".

Also please post what have you tried till now.

PBUH

Go to Top of Page

Chris_1
Starting Member

United Kingdom
3 Posts

Posted - 10/26/2011 :  12:28:18  Show Profile  Reply with Quote
Sorry, what I mean is: The linked former account is returned on the next row. The results need to be sorted by balance of current account, but the balance of the former account needs to be ignored when sorting the entire results, and should only be sorted in descending order in relation to it's current linked account. Reading that back has confused me too :s

I suppose the best way to explain it is that the returned results are broken down in to sub-results for each person on the system. Each st of sub-results is ordered Current, Former, Former, for example making up 3 rows. Then all of these sub-results are put together in one big result in the order of current balance descending.

As for an example, I have not really started it yet. I just need an approach that might work. Sorry.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.11 seconds. Powered By: Snitz Forums 2000