Click here to Skip to main content
15,891,372 members
Home / Discussions / Database
   

Database

 
GeneralRe: How to create data copies SQL Server 2005 Express ? Pin
Mycroft Holmes17-Dec-14 21:39
professionalMycroft Holmes17-Dec-14 21:39 
GeneralRe: How to create data copies SQL Server 2005 Express ? Pin
Member 245846721-Dec-14 17:01
Member 245846721-Dec-14 17:01 
QuestionChange cursor to common table Pin
Amr Mohammad15-Dec-14 1:16
Amr Mohammad15-Dec-14 1:16 
SuggestionRe: Change cursor to common table Pin
Richard Deeming15-Dec-14 2:56
mveRichard Deeming15-Dec-14 2:56 
GeneralRe: Change cursor to common table Pin
Amr Mohammad15-Dec-14 8:22
Amr Mohammad15-Dec-14 8:22 
AnswerRe: Change cursor to common table Pin
Richard Deeming15-Dec-14 10:32
mveRichard Deeming15-Dec-14 10:32 
GeneralRe: Change cursor to common table Pin
Amr Mohammad16-Dec-14 21:40
Amr Mohammad16-Dec-14 21:40 
GeneralRe: Change cursor to common table Pin
Richard Deeming17-Dec-14 2:05
mveRichard Deeming17-Dec-14 2:05 
I still think the query you posted is double-counting:
  • You get the total for account A;
  • You then loop through the child accounts:

    • You get the total for account A.1 and its parent account (account A), and add it to the total;
    • You get the total for account A.2 and its parent account (account A), and add it to the total;
  • Etc.

By the time you've finished, you've added the total for account A multiple times - once for each child account.

From your description, you just want to get the total balance for an account and its descendants, which means that your original query isn't correct.

My previous answer had a link to an article explaining recursive CTEs: How to use recursive CTE calls in T-SQL[^]
Google also returns the documentation on TechNet: http://technet.microsoft.com/en-us/library/ms186243%28v=sql.105%29.aspx[^]
And a blog post: http://blog.sqlauthority.com/2012/04/24/sql-server-introduction-to-hierarchical-query-using-a-recursive-cte-a-primer/[^]



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: Change cursor to common table Pin
Amr Mohammad17-Dec-14 3:32
Amr Mohammad17-Dec-14 3:32 
QuestionHow can you tell if a SQL Server instance max'ed out bottleneck is Memory? Pin
devvvy11-Dec-14 4:20
devvvy11-Dec-14 4:20 
AnswerRe: How can you tell if a SQL Server instance max'ed out bottleneck is Memory? Pin
Tim Carmichael11-Dec-14 4:23
Tim Carmichael11-Dec-14 4:23 
GeneralRe: How can you tell if a SQL Server instance max'ed out bottleneck is Memory? Pin
M Riaz Bashir11-Dec-14 15:07
M Riaz Bashir11-Dec-14 15:07 
QuestionMySQL Export Problem Pin
M Riaz Bashir10-Dec-14 22:46
M Riaz Bashir10-Dec-14 22:46 
AnswerRe: MySQL Export Problem Pin
Eddy Vluggen11-Dec-14 4:59
professionalEddy Vluggen11-Dec-14 4:59 
QuestionDatabase Mail Not sending Email Pin
Robymon8-Dec-14 20:56
Robymon8-Dec-14 20:56 
QuestionDo I have to have SQL Server Express installed? Pin
jkirkerx30-Nov-14 11:31
professionaljkirkerx30-Nov-14 11:31 
AnswerRe: Do I have to have SQL Server Express installed? Pin
Richard MacCutchan30-Nov-14 21:30
mveRichard MacCutchan30-Nov-14 21:30 
GeneralRe: Do I have to have SQL Server Express installed? Pin
jkirkerx2-Dec-14 10:21
professionaljkirkerx2-Dec-14 10:21 
AnswerRe: Do I have to have SQL Server Express installed? Pin
Eddy Vluggen2-Dec-14 7:27
professionalEddy Vluggen2-Dec-14 7:27 
GeneralRe: Do I have to have SQL Server Express installed? Pin
jkirkerx2-Dec-14 10:25
professionaljkirkerx2-Dec-14 10:25 
Questionsql server import export wizard stored procedure? Pin
iamvinod3426-Nov-14 18:57
iamvinod3426-Nov-14 18:57 
AnswerRe: sql server import export wizard stored procedure? Pin
Mycroft Holmes26-Nov-14 20:09
professionalMycroft Holmes26-Nov-14 20:09 
AnswerRe: sql server import export wizard stored procedure? Pin
jschell27-Nov-14 6:02
jschell27-Nov-14 6:02 
QuestionNeed to Truncate a table and populate the rest of the tables Pin
Hari-CodeBlogger25-Nov-14 0:30
Hari-CodeBlogger25-Nov-14 0:30 
QuestionRe: Need to Truncate a table and populate the rest of the tables Pin
Shweta N Mishra26-Nov-14 4:35
professionalShweta N Mishra26-Nov-14 4:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.