Sum fields by invoicenumber - sql

I need to do an update of fields in a table - but only if the sum of a field differs from the sum of fields in another table.
Something along these lines:
if sum (KundFaktura.FakturaBeloppUtl) <> SUM (KundFakturaHandelser.BeloppUtl) **then update**
The summation need these conditions:
KundFakturaHandelser.FakturaNr
KundFaktura.FakturaNr

Related

Summing to columns into a third column in SSRS

I have two columns in.column1, ou.column2. I would like to place a third column next to them that totals the number from both columns. I have tried an expression=sum(Fields!in.coulmn1.value,"new_dataset") +(Fields!in.coulmn2.value,"new_dataset")this does not give me the correct answer. Any help appreciated!
When trying the above expression I get a total that does not equal the total of the two columns.
Your code is summing all records in the dataset. If you just want totals per row, try removing the Sum call. Something like...
= Fields!in.column1.value + Fields!in.column2.value

Need SQL query in Access to Show Total Sales by Catalog#

I have a table named Sales_Line_Items. In it I have the following fields; order#, Catalog#, Whole_Sale_Price, Qty_Ordered. I have created a query using this table that sums up the Qty_Ordered field and returns a Revenue field with a total per order line. What I need is a query that shows me each the quantity of each item sold and the total sales by item. This is the query I wrote for the total revenue:
SELECT
Sales_Line_Items.[Order#],
Sales_Line_Items.[Catalog#],
Sales_Line_Items.Wholesale_Price,
Sum(Sales_Line_Items.Qty_Ordered) AS SumOfQty_Ordered,
Sum(Sales_Line_Items.[Qty_Ordered]*Sales_Line_Items.[Wholesale_Price]) AS Revenue
FROM Sales_Line_Items
GROUP BY
Sales_Line_Items.[Order#],
Sales_Line_Items.[Catalog#],
Sales_Line_Items.Wholesale_Price;
The result was a new field with header ' Revenue'. The other fieds listed are Order#, Catalog#, Wholesale_Price, and SumofQty_Ordered fields. This is fine, if I want to know what every sales line totals up to within each order. But I want to show the total sold by Catalog# so that I can view each product sales total.
I was able to figure this out by adding the Totals line in Design View, and grouping by Expression in the query field and leaving the Catalog# field alone. The query I used looks like this;
Total: Sum([Sales_Line_Items]![Wholesale_Price]*[Sales_Line_Items]![Qty_Ordered])

Question about divide result from the same column in SQL Server

I am trying to write statement in SQL Server. What I am trying to do is to get the result of count records in columns end with "R" divide the count of all the records. So it is basically the statement of a column with a statement " count (invoice) where Invoice like "%R" / count( Invoice)"
Here is my code without the divide calculation. I only come up with statement without the divide calculation.
SELECT
Invoice,
COUNT(ART_CURRENT__TRANSACTION.Invoice) AS Number_Revisions,
MAX(ART_CURRENT__TRANSACTION.[Customer]) AS "Customer",
MAX(ARM_MASTER__CUSTOMER.Name) AS "Name",
MAX(ART_CURRENT__TRANSACTION.[Job]) AS Job
FROM
ART_CURRENT__TRANSACTION
LEFT OUTER JOIN
ARM_MASTER__CUSTOMER ON ARM_MASTER__CUSTOMER.Customer = ART_CURRENT__TRANSACTION.Customer
WHERE
Invoice LIKE '%R'
GROUP BY
Invoice;
What I am trying to ask is how can I add a column that calculate the number of invoice end with "R"/ NUMBER OF INVOICE.
Thank you guys!
What I am trying to do is to get the result of count records in Columns end with "R" divide the count of all the records.
You seem to want this calculation:
SELECT AVG(CASE WHEN t.Invoice LIKE '%R' THEN 1.0 ELSE 0 END)
FROM ART_CURRENT__TRANSACTION t;
This assumes that invoice is in the transaction table. I don't think a join is necessary for what you want to do.

Can't get A sum to join to a table

I have two tables, one contains a set of line items with amounts:
LEDGERTRANS:
Invoice ID LineAmount
CM-00011054 -122.500000000000
CM-00011054 -246.000000000000
CM-00011054 -159.840000000000
CM-00011054 -39.3600000000000
And one with an item number i want, which happens to have a field, AMOUNTMST that is the sum of the above amounts
CUSTINVOICETRANS
INVOICE ID AMOUNTMST
110100 -567.700000000000
400100 567.700000000000
I would like to take the sum of the CustInvoiceTrans lines, then grab the corresponding invoice id from the LedgerTrans Table.
This is for SQL Server 2008R2.
As I said, all I want is the InvoiceId. I think i'm making this too complicated. any help appreciated

How to add a rdlc group's totals row for an outer group's totals row

I have a 2-level group report (rdlc). The inner group (GroupA) has in its totals row, totals of all record values, except one value which is the same for all records and for which that is the value I need to show(let's call that X). So the totals row looks like
Sum,Sum,....X
To do this I use Sum(Fields!,"GroupA") for all cells except this one, which is Fields!X.Value;
The outer group (Group B) must add all these values and display their sums in its totals row. The desired output should be:
Sum,Sum,.....Sum
So for all other fields, I use Sum(Fields!,"Group2").
What must I use for the X field? If I use Sum(Fields!X.Value,"Group2") it will add X as many numbers as there are records, where I want to add X for each group.
I really would appreciate a quick answer on this as I have to fix this problem yesterday :)
thanks
c.