Join Two Tables and calculate SUM of Column in SQL Server

Last Reply 7 months ago By pandeyism

Posted 7 months ago

Hi,

I want yo generate a chart using data from two tables. I developed the code in Visual Studio, C# and I took the code for chart from this site.

I had two tables: Invoices and Costs.

Invoices contains: category,due_date, sum.

Costs contains: category, date, sum.

I select a month from Costs and then I want to display on the chart the total sum of the tables and all the categories once time.

How can I write the SQL query?

I share with you my current query on Costs table.

 string query = string.Format("select distinct Categorie,sum(C_Suma) from Cheltuieli where  datename(month,C_Data) = '{0}' group by Categorie", ddlLuna.SelectedValue);

The code is in Romanian, I translate above the terms.

Thank you!

You are viewing reply posted by: chetan 7 months ago.
Posted 7 months ago

Hi ada20...

select distinct Categorie,sum(C_Suma) from Cheltuieli

There is no table called Cheltuieli.

You have mentioned only 2 tables ie.Invoices and Costs