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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:19:36+00:00 2026-06-02T12:19:36+00:00

I have 3 tables: DimAccounts, DimTime and FactBudget. DimAccounts example: AccountKey Accouncode AccountType AccountFrom

  • 0

I have 3 tables: DimAccounts, DimTime and FactBudget.

DimAccounts example:

AccountKey  Accouncode  AccountType   AccountFrom   AccountTo 
1.10001     10001       S                  11401    27601
1.10002     10002       S                  11401    16501
1.11000     11000       S                  11401    11508
1.110001    110001      B                   NULL    NULL
1.110002    110002      B                   NULL    NULL
1.11400     11400       S                  11401    11408

DimTime example:

   TimeKey      FullDate
    20020102    2002-01-02
    20020103    2002-01-03
    20020104    2002-01-04

FactBudget example:

TimeKey     AccountKey              Debit    Credit
20080523    1.110002                0.00    884.00
20080523    1.110001                0.00    4251.96
20100523    1.100002                229.40  0.00
20080523    1.100002                711.79  0.00
20090523    1.110002                0.00    711.79
20080523    1.110001                0.00    229.40
20040523    1.100002                0.00    15619.05

In FactBudget are many Accounts just with type B. I need to calculate Debit and Credit Sums where Account type is S (Sum). Columns AccountFrom and AccountTo shows B Type Accounts from where to begin summing (AccountFrom ) and where end (AccountTo).

I have made solution using Cursors…. buth you know this is very bad 🙂 I think there somehow to Group data in FactBudget (because there also many columns in factbudget and rows 600k) and when search for solution (when I group left just 60k rows):

SELECT [TimeKey], 
       [AccountKey], 
       SUM([Debit]), 
       SUM([Credit]) 
FROM   [dbo].[FactBudget] 
GROUP  BY [TimeKey], 
          [AccountKey] 

So, How to get S Accounts Debit and Cred Sum by TimeKey and AccountKey? (AccountKey datatype is nvarchar)

Solution example:

TimeKey     AccountKey  Debit    Credit
20080523    1.10002     0.00    2500
20080523    1.11000     0.00    8000
20080524    1.10002     900  0.00

In Fact budget there is no Account with type S!!!! we need to get it (example 1.11000 just for date 20080523):

select 
SUM(Debit), SUM(Credit)
from FactBudget
LEFT JOIN [DimAccounts]
ON [DimAccounts].[AccountKey] = FactBudget.[AccountKey]   
where CAST([DimAccounts].AccountCode AS INT) >=11401    
and CAST([DimAccounts].AccountCode AS INT) <= 11508
and FactBudget.Timekey = 20080523

But I need each S Account Debit and credit Sum by date.

  • 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-02T12:19:37+00:00Added an answer on June 2, 2026 at 12:19 pm

    As far as I can see, you need to join DimAccounts to itself to associate B-type accounts with their corresponding S-type accounts, then join that row set to FactBudget to finally obtain the figures. Something like this:

    SELECT
      f.TimeKey,
      s.AccountKey,
      SUM(f.Debit) AS Debit,
      SUM(f.Credit) AS Credit
    FROM DimAccounts s
      INNER JOIN DimAccounts b ON b.AccountCode BETWEEN s.AccountFrom AND s.AccountTo
      INNER JOIN FactBudget  f ON f.AccountKey = b.AccountKey
    WHERE s.AccountType = 'S'
      AND b.AccountType = 'B'
    GROUP BY
      f.TimeKey,
      s.AccountKey
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 tables: DimAccounts and FactBudget. DimAccounts example: AccountKey AccountCode AccountName AccountGroup AccountType
In my database I have tables that define types for example Table: Publication Types
I have tables A and B with identity PKs ida and idb : ex
I have tables like these two test_table date student test 2012-05-31 Alice Math 2012-05-31
I have tables like this: tblUsers int UserID string UserName tblUsersInRoles int UserID int
I have tables linked by FK, I query on the first table using entity
I have tables named news and tags_news. Given a news id I have to
I have tables Product ( ID, CategoryID, ... ) Category ( ID, Name, ..
In the database we have tables called Sites, Organisations, Person, Department have the same
I used to have tables before to display the content and people here advised

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.