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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:43:20+00:00 2026-06-15T14:43:20+00:00

I am trying to create a year to date report that lists all clients

  • 0

I am trying to create a year to date report that lists all clients with the totals from all invoices from the current date since the beginning of the year. I also want to join the same total columns from a budgeting table so they are able to compare actual vs budget. I am able to join the clients to the Invoices and get their totals correctly, but I am not able to get the correct values when I join the budgets table.

tbl_Clients

– ID uniqueidentifier

– Name varchar(100)

– isActive bit

– isDeleted bit

tbl_Invoices

-ClientID uniqueidentifier

-Month int

-Year int

-Energy int

-Demand int

-DemandDollar decimal(18,2)

-EnergyDollar decimal(18,2)

-IsActive bit

-IsDeleted bit

tbl_Budgets

-ClientID uniqueidentifier

-Month int

-Year int

-Energy int

-Demand int

-DemandDollar decimal(18,2)

-EnergyDollar decimal(18,2)

-IsActive bit

-IsDeleted bit

This procedure currently works to get each clients totals from tbl_Invoices. I’m just not sure how to then add the tbl_Budgets table totals as 5 more columns. The Mills column from the budget table is calculated in the same fashion.

Here is the procedure I currently have with the static values of 2012 and 9(September) They will eventually be parameters in a stored proc.

Select cli.name
    , Sum(inv.DemandDollar) as DemandDollar
    , SUM(inv.EnergyDollar) as EnergyDollar
    , Sum(inv.Energy) as Energy
    , Sum(inv.Demand) as Demand
    , Mills = 
        (
        case when sum(inv.Energy) = 0
        then 0.00
        else
        Cast((((sum(inv.DemandDollar) + sum(inv.EnergyDollar))/sum(inv.Energy))* 1000) as decimal(18,2))
        end 
        )

from tbl_Clients cli
join tbl_Invoices inv
on inv.ClientID = cli.ID

where cli.IsActive = 1 and cli.IsDeleted = 0 
and inv.IsActive = 1 
and inv.IsDeleted = 0 and inv.Year = 2012 and inv.Month <= 9 
group by cli.name
  • 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-15T14:43:21+00:00Added an answer on June 15, 2026 at 2:43 pm

    The first thing you need to ask yourself is whether clients that have no invoices can have budgets and do they need to be included? Also, can clients that have no budgets have invoices? Does every client that has an invoice have a budget and does every client that has a budget have an invoice? The answers to these questions will effect how you structure your query.

    So maybe this, which picks up all budgets and invoices regardless:

    SELECT cli.Name, SUM(UsedDollar) AS UsedDollar, SUM(BudgetDollar) AS BudgetDollar
    (SELECT ClientID, EnergyDollar AS UsedDollar, 0.0 AS BudgetDollar
    FROM tbl_Invoices
    WHERE Year = 2012 AND Month <= 9
    UNION ALL
    SELECT ClientID, 0.0 AS UsedDollar, EnergyDollar AS BudgetDollar
    FROM tbl_Budgets
    WHERE Year = 2012 AND Month <= 9
    ) DT 
    INNER JOIN tbl_Clients cli ON DT.ClientID = cli.ID
    GROUP BY cli.Name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a Crystal Report that reads data from an access table.
I'm trying to create an expiration date using values selected from drop down lists
I am trying to create a db that has a year attribute but I
I'm trying to create a Date like this: date = new Date(year-1900, mon-1, day,
I'm trying to create a string with the current time and date time_t t
Im trying to create a php function that converts a string date to a
Using PHP/MySQL I'm trying to create a select statement that gets the data from
Trying to create Database as follows: USE Master GO IF NOT EXISTS(SELECT [Name] FROM
Suppose that expire date of employees is defined as one year after hire_date. I
I’m trying to create a date in the BC era, but failing pretty hard.

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.