Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Return multiple column results in same column.

Author  Topic 

Chris_1
Starting Member

3 Posts

Posted - 2011-10-26 : 12:18:52
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

3 Posts

Posted - 2011-10-26 : 12:21:25
Edit: Former accounts in descending order of balance.
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2011-10-26 : 12:21:32
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

3 Posts

Posted - 2011-10-26 : 12:28:18
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
   

- Advertisement -