ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Join Two Tables and calculate SUM of Column in SQL ServerHi @ada20,<br />Please try the following<br /><br /><a href = 'link(Threads/107769/Join-Two-Tables-and-filter-records-in-SQL-Server/)'>Join Two Tables and filter records in SQL Server</a><br /><br />It might help you.<br /><br />Cheers Andrea.https://www.aspforums.net:443/Threads/214442/Join-Two-Tables-and-calculate-SUM-of-Column-in-SQL-Server/https://www.aspforums.net:443/Threads/214442/Join-Two-Tables-and-calculate-SUM-of-Column-in-SQL-Server/Mon, 17 Jun 2019 14:32:56 GMTJoin Two Tables and calculate SUM of Column in SQL Server<p>Hi ada20...</p> <p>select distinct Categorie,sum(C_Suma) from Cheltuieli</p> <p>There is no table called Cheltuieli.</p> <p>You have mentioned only 2 tables ie.Invoices and Costs</p>https://www.aspforums.net:443/Threads/214442/Join-Two-Tables-and-calculate-SUM-of-Column-in-SQL-Server/https://www.aspforums.net:443/Threads/214442/Join-Two-Tables-and-calculate-SUM-of-Column-in-SQL-Server/Mon, 17 Jun 2019 22:45:50 GMTJoin Two Tables and calculate SUM of Column in SQL Server<p>Cheltuieli means Costs.&nbsp;</p>https://www.aspforums.net:443/Threads/214442/Join-Two-Tables-and-calculate-SUM-of-Column-in-SQL-Server/https://www.aspforums.net:443/Threads/214442/Join-Two-Tables-and-calculate-SUM-of-Column-in-SQL-Server/Mon, 17 Jun 2019 23:47:29 GMTJoin Two Tables and calculate SUM of Column in SQL Server<p>Hi <a class="username" rel="ada20">ada20</a>,</p> <p>Refer below sample query.</p> <p><span style="text-decoration: underline;"><strong>SQL</strong></span></p> <pre class="brush: sql">DECLARE @Invoices AS TABLE(category VARCHAR(MAX),due_date DATETIME, [sum] INT) INSERT INTO @Invoices VALUES(&#39;Stationary accessories&#39;,&#39;2019/08/16&#39;,1250) INSERT INTO @Invoices VALUES(&#39;Grocery ingredients&#39;,&#39;2019/08/17&#39;,5000) INSERT INTO @Invoices VALUES(&#39;Electronic accessories&#39;,&#39;2019/08/18&#39;,2000) INSERT INTO @Invoices VALUES(&#39;beautician accessories&#39;,&#39;2019/08/19&#39;,2000) DECLARE @Costs AS TABLE(category VARCHAR(MAX),[date] DATETIME, [sum] INT) INSERT INTO @Costs VALUES(&#39;Stationary accessories&#39;,&#39;2019/08/16&#39;,1250) INSERT INTO @Costs VALUES(&#39;Grocery ingredients&#39;,&#39;2019/08/17&#39;,2000) INSERT INTO @Costs VALUES(&#39;Electronic accessories&#39;,&#39;2019/08/18&#39;,2000) INSERT INTO @Costs VALUES(&#39;beautician accessories&#39;,&#39;2019/08/19&#39;,2000) SELECT i.category, SUM(i.[sum]) + SUM(c.[sum]) Suma, c.[date] FROM @Invoices i INNER JOIN @Costs c ON c.category = i.category WHERE DATENAME(MONTH,c.[date])=&#39;August&#39; GROUP BY i.category,c.[date]</pre> <p><strong><span style="text-decoration: underline;">Output</span></strong></p> <table border="1"> <tbody> <tr> <td><strong>category</strong></td> <td><strong>Suma</strong></td> <td><strong>date</strong></td> </tr> <tr> <td>beautician accessories</td> <td>4000</td> <td>2019-08-19 00:00:00.000</td> </tr> <tr> <td>Electronic accessories</td> <td>4000</td> <td>2019-08-18 00:00:00.000</td> </tr> <tr> <td>Grocery ingredients</td> <td>7000</td> <td>2019-08-17 00:00:00.000</td> </tr> <tr> <td>Stationary accessories</td> <td>2500</td> <td>2019-08-16 00:00:00.000</td> </tr> </tbody> </table> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/214442/Join-Two-Tables-and-calculate-SUM-of-Column-in-SQL-Server/https://www.aspforums.net:443/Threads/214442/Join-Two-Tables-and-calculate-SUM-of-Column-in-SQL-Server/Tue, 18 Jun 2019 00:10:30 GMT