Joining two tables in Microsoft Report Viewer (SSRS 2012) - c#

I have two database tables
Invoice Table (PK InvoiceNo)
InvoiceDate | InvoiceNo | Name | Class | AmountPaid
2014-6-5 | B001 | ABC | E1 | 1500.00
2014-6-5 | B002 | BCD | E1 | 2000.00
2014-6-5 | B003 | CDE | E3 | 1000.00
2014-6-5 | B004 | ABC | E3 | 3000.00
2014-6-6 | B005 | BCD | E2 | 5000.00
2014-6-6 | B006 | CCD | E1 | 2000.00
Expences Table (PK Date,Description)
Date | Description | Cost
2014-6-5 | Lunch | 150.00
2014-6-5 | SoftDrink | 50.00
2014-6-6 | BusFair | 10.00
I want to create a report using these two tables. What I expect is
InvoiceDate | InvoiceNo | Name | Class | AmountPaid | Description | Cost
2014-6-5 | B001 | ABC | E1 | 1500.00 | Lunch | 150.00
| B002 | BCD | E1 | 2000.00 | SoftDrink | 50.00
| B003 | CDE | E3 | 1000.00 |
| B004 | ABC | E3 | 3000.00 |
2014-6-6 | B005 | BCD | E2 | 5000.00 | BusFair | 10.00
| B006 | CCD | E1 | 2000.00 |
But my output looks like this
InvoiceDate | InvoiceNo | Name | Class | AmountPaid | Description | Cost
2014-6-5 | B001 | ABC | E1 | 1500.00 | Lunch | 150.00
| B002 | BCD | E1 | 2000.00 | Lunch | 150.00
| B003 | CDE | E3 | 1000.00 | Lunch | 150.00
| B004 | ABC | E3 | 3000.00 | Lunch | 150.00
| B001 | ABC | E1 | 1500.00 | SoftDrink | 50.00
| B002 | BCD | E1 | 2000.00 | SoftDrink | 50.00
| B003 | CDE | E3 | 1000.00 | SoftDrink | 50.00
| B004 | ABC | E3 | 3000.00 | SoftDrink | 50.00
2014-6-6 | B005 | BCD | E2 | 5000.00 | BusFair | 10.00
| B006 | CCD | E1 | 2000.00 | BusFair | 10.00
Please help me to resolve this problem...

You're running into 2 problems here:
You need to add an SSRS Group for both InvoiceDate and Description, and configure the Description field on the table in the same manner that you seem to have already done for InvoiceDate (so it only appears on the group row, not in the details).
Your "Expences" table should NOT be using Date + Description as a PK. It should have its own "ExpenceID" type field, and an "InvoiceNO" FK back to your "Invoice" table. Without proper keys, joining only on "Date" is going to cause a cartesian.
Note that #2 is more critical than #1 - until you fix your data issue, you're going to have a bad time.

Related

How to list the products under each category in sql? side by side

I'm a bit of a beginner in sql and I need your help.
I'm sorry that I don't know if the question is correct.
now the code gives this;
+---------+----------+-------------+------------+
| id | CompanyId| DealId | price |
+---------+----------+-------------+------------+
| 1 | 1 | 1 | 100 |
| 2 | 1 | 2 | 50 |
| 3 | 1 | 3 | 25 |
| 4 | 2 | 1 | 1000 |
| 5 | 2 | 2 | 2000 |
| 6 | 2 | 3 | 2500 |
+---------+----------+-------------+------------+
but this is what i want;
+---------+----------+-------------+------------+------------+--+
| id | companyId| DealName1 | DealName2 | DealName3 | |
+---------+----------+-------------+------------+------------+--+
| 1 | 1 | 100 | 50 | 25 | |
| 2 | 2 | 1000 | 2000 | 2500 | |
| 3 | 3 | value | value | value | |
| 4 | 4 | value | value | value | |
+---------+----------+-------------+------------+------------+--+
select CompanyId
,[1] as DealName1
,[2] as DealName2
,[3] as DealName3
from (select CompanyId, DealId, price from t) t
pivot (sum(price) for DealId in([1],[2],[3])) p
CompanyId
DealName1
DealName2
DealName3
1
100
50
25
2
1000
2000
2500
Fiddle

Inserting row between different cell values

I am attempting to write from a DataTable to Excel file and I want to insert a blank row in between each 'WO Base ID' I am not sure how to approach this. I am using C# with .NET, I am using the package EPPlus, I understand how to add a new row and all that with EPPlus but I cannot figure out how to split the 'WO Base IDs" up. Any help is appreciated.
Original Output
+---------------+------------+------------+-----------+-------------+-------------+
| Part # | Close Date | WO Base ID | WO Sub ID | Resource ID | Desired Qty |
+---------------+------------+------------+-----------+-------------+-------------+
| F-COM-95650-1 | 12-04-2001 | WO05837 | 0 | KITTING | 50 |
| F-COM-95650-1 | 12-04-2001 | WO05837 | 0 | PACKAGING | 50 |
| F-COM-95650-1 | 03-20-2002 | WO06008 | 0 | KITTING | 50 |
| F-COM-95650-1 | 03-20-2002 | WO06008 | 0 | PACKAGING | 50 |
| F-COM-95650-1 | 05-01-2002 | WO06231 | 0 | KITTING | 50 |
| F-COM-95650-1 | 05-01-2002 | WO06231 | 0 | PACKAGING | 50 |
| F-COM-95650-1 | 11-07-2002 | WO06994 | 0 | KITTING | 250 |
| F-COM-95650-1 | 11-07-2002 | WO06994 | 0 | PACKAGING | 250 |
+---------------+------------+------------+-----------+-------------+-------------+
Desired Output
+---------------+------------+------------+-----------+-------------+-------------+
| Part # | Close Date | WO Base ID | WO Sub ID | Resource ID | Desired Qty |
+---------------+------------+------------+-----------+-------------+-------------+
| F-COM-95650-1 | 12-04-2001 | WO05837 | 0 | KITTING | 50 |
| F-COM-95650-1 | 12-04-2001 | WO05837 | 0 | PACKAGING | 50 |
| F-COM-95650-1 | 03-20-2002 | WO06008 | 0 | KITTING | 50 |
| F-COM-95650-1 | 03-20-2002 | WO06008 | 0 | PACKAGING | 50 |
| F-COM-95650-1 | 05-01-2002 | WO06231 | 0 | KITTING | 50 |
| F-COM-95650-1 | 05-01-2002 | WO06231 | 0 | PACKAGING | 50 |
| F-COM-95650-1 | 11-07-2002 | WO06994 | 0 | KITTING | 250 |
| F-COM-95650-1 | 11-07-2002 | WO06994 | 0 | PACKAGING | 250 |
+---------------+------------+------------+-----------+-------------+-------------+

Aggregate multiple columns in DataTable and put result to new DataTable

Hi i have a DataTable with following data formating. I am trying to aggregate in C# on condition. I am a Newbie to Linq.
Profile | Nr | Result|
------------------------
A | 1 | OK |
A | 2 | NOK |
A | 2 | OK |
A | 3 | OK |
A | 4 | OK |
A | 5 | OK |
BB | 1 | OK |
BB | 2 | NOK |
BB | 2 | NOK |
BB | 2 | OK |
BB | 3 | OK |
BB | 4 | OK |
BB | 5 | OK |
I Want to aggregate by first columnt (Profile) and count rows where the Result is OK.
The expected result should be a new DataTable and should look like this.
Profile | Count|
----------------
A | 5 |
BB | 5 |
How can i do this in C# ?

MySQL Subquery Display in UPPERCASE

[DONE] for those who need this.. I will edit this and put the answer below..
How to make LName and FName all CAPS using subquery?
I already make all LName and FName CAPS but not in subquery using this code
Select UPPER(LName) AS "Lastname", UPPER(FName) AS "Firstname" FROM Trainers;
OUTPUT:
+-----------+-----------+
| Lastname | Firstname |
+-----------+-----------+
| MONTANO | GERALD |
| ALEJANDRO | LEONARD |
| MONTEZ | GARY |
| GUILLERMO | JACKIE |
| SANCHEZ | VERNA |
| GABORNI | MICHELLE |
+-----------+-----------+
Table Trainers
+-----------+-----------+----------+-------+
| TrainerNo | LName | FName | Rate |
+-----------+-----------+----------+-------+
| 00804871 | Montano | Gerald | 200 |
| 00807461 | Alejandro | Leonard | 175 |
| 00807462 | Montez | Gary | 150 |
| 00823253 | Guillermo | Jackie | 200 |
| 00827320 | Sanchez | Verna | 125 |
| 00845907 | Gaborni | Michelle | 150 |
+-----------+-----------+----------+-------+
ANSWER:
Select UPPER(Lname) AS "Lastname", UPPER(FName) AS "Firstname" from Trainers Where Rate <= (Select Max(Rate) from Trainers);
IF you want to return the first name concatenated with the second name in upper case in a sub-query. Then you can do this.
Select * from Table Name, (Select UPPER(LName) + UPPER(FName) FROM Trainers) as Name

MYSQL - Rows to Columns using join statement

I have to get data from 2 tables using join.1st table Name is sliprecord
+-------+-----------+-----------------------+---------+
| cid | cname | date | totalAmount |
+-------+-----------+-----------------------+---------+
| 8 | Umer | 2015-12-15 | 1000 |
| 9 | Shakir | 2015-12-20 | 2000 |
+-------+-----------+-----------------------+---------+
Another table Name is expense
+-------+-----------+-----------------------+---------+
| idExpense | title | date | amount |
+-------+-----------+-----------------------+---------+
| 1 | BreakFast | 2015-12-15 | 300 |
| 2 | Lunch | 2015-12-15 | 500 |
| 3 | Dinner | 2015-12-17 | 700 |
+-------+-----------+-----------------------+---------+
I want to create balance sheet, If sliprecord Table don't have a date in expense Table then it should also give me sliprecord date and sliprecord totalAmount .
And If expense don't have a date in sliprecord Table then it should also give me expense title,expense date,and expense amount .
Desired Out put should be like this:
+-------+-----------+-----------------------+---------+
| title | EXP_date | amount | Slip_date | totalAmount
+-------+-----------+-----------------------+---------+
| BreakFast | 2015-12-15 | 300 |2015-12-15 | 1000
| Lunch | 2015-12-15 | 500 | |
| Dinner | 2015-12-17 | 700 |
| | | |2015-12-20 | 2000
+-------+-----------+-----------------------+---------+

Categories