I have this queries:
select idCustumer, Name, Address from Customer
This give me the header of the report, and this one:
select idCustomer, Description, Sum(Total) as Total from Product group by Description
First query runs:
idCustomer Name Address
1 Phil Fake Av. 1234
2 John Fake Av. 4321
The second:
idCustomer Description Sum(Total)
1 PROD01 10
1 PROD02 20
2 PROD01 30
When i use generate a report using one customer it's ok. The problem is with 2 or more customers in the same report.
What i do?
I create 1 dataset with 2 tables (1 per query) linking them by idCustomer. I create a report using this dataset, the first table (header) works fine, it prints my four test customers.
Then i add a SubReport.
rpt.Subreports(0).SetDataSource(subReportes.Tables(1)) 'Tables(1) is 2nd Query
But this print the same info again and again.
My Report:
Customer: Phil Address: Fake Av. 1234
Order:
PROD01 10
PROD02 20
PROD01 30
Total 60
Customer: John Address: Fake Av. 4321
Order:
PROD01 10
PROD02 20
PROD01 30
Total 60
Is there a guide or link where i can learn how to include this subreport so i get (or if there is a another way to accomplish this?)
Customer: Phil Address: Fake Av. 1234
Order:
PROD01 10
PROD02 20
Total 30
Customer: John Address: Fake Av. 4321
Order:
PROD01 10
Total 10
I'm using VS 2010 (VB), SQL Server 2008 R2, Crystal Report 2010
Thanks!
Your design is totally wrong. First you need to write a procedure in TSQL like this
SELECT C.idCustomer CustomerId, C.Name Name, C.Address Address, P.Description Description, P.Total Total
FROM CUSTOMER C
INNER JOIN PRODUCT P
ON C.idCustumer = P.idCustomer
And add set this proc as the datasource for the report.
Then you have to do a grouping for field, CustomerId in the report. After that you need to place the customer details in the group header section and the order details in the Details section. And also to get the total value for the you have to use the summary field in crystal reports
Related
Reporting Question
I have been asked to see if Visual Studio could format a report like below.
here is a bit of data that was pulled via SQL query from ERP system.
ORDER CUSTOMER DUE DATE LINE# ITEM QTY VENDORPO PO DUE DATE QTY
123 1/21/2022 1 WIDGET 123 10 4540 1/20/2021 5
152 1/31/2022 1 WIDGET 123 25 4546 2/1/2021 10
152 2/15/2022 2 WIDGET 123 25 4592 3/1/2021 50
Is there a way to make a report in visual so that it looks like this
ORDER CUSTOMER DUE DATE LINE# ITEM QTY VENDOR PO PO DUE DATE QTY
123 1/21/2022 1 WIDGET 123 10 4540 1/20/21 5
4546 2/1/21 5
152 1/31/2022 1 WIDGET 123 25 4546 2/1/21 5
4592 3/1/21 20
152 2/15/2022 2 WIDGET 123 25 4592 3/1/2022 25
INVENTORY BALANCE 5
Our reporting will not give an accurate open order report with expected purchase order delivery dates that we can send to our customers. Just wondering if Visual could be scripted to do what we wanted.
thank you for any input!
WITH prod AS
(SELECT points_spent,price_of_item,channel FROM transaction_history
where channel=?
)
SELECT *
from prod pivot (sum(points_spent) for (channel) in ('AP' as rpts_admin_portal , 'MB' as rpts_member_portal ),
SUM(price_of_item) FOR (channel) IN ('AP' fifty_percent_cashback_price,'MB' retail_price)
I have tried to achieve to show the column name dynamically using pivot. Here i need to show above two columns name such as when user purchasing an item via member portal need to show the rpts_member_portal,if it admin portal need to show like rpts_admin_portal. price_of_item also similar. But i can achieve for only one column in oracle. how to do this for price_of_item also. Help me to overcome this problem.
Actual data is
points_spent price_of_item channel
============ ============= ==============
100 100 AP
50 100 MB
Expected result set is if channel is Admin portal
rpts_admin_portal fifty_percent_cashback_price channel
================= ============================= ==========
100 100 AP
if it is member portal expected result set is
rpts_member_portal retail_price channel
================= ============================= ==========
50 50 MB
I have two tables named 'Customers' and 'Committeetables' in mysql database. They have following columns
Table: Customer
nd Name FatherName Cell# AdvanceAmount
25 Waseem Asghar 0302 2500
30 Ramzan Khan 0303 3500
35 Rana Ali 0307 2000
Table: CommitteeTables
nd Amount RecievingDate DrawDate
25 1500 2-10-15 10-10-15
30 1500 2-10-15 10-10-15
25 1500 3-10-15 10-11-15
30 1500 3-10-15 10-11-15
35 1500 3-10-15 10-11-15
A Column 'nd' in 'Customers' table is primary key and in 'CommitteeTables' table is foreign key. It means 'Customers' table joins with 'ComitteeTables' table through 'nd' column.
Expected Result table should be as under:
nd Name Father Name Cell# Advance Amount Balance
25 Waseem Asghar 0302 25000 3000 22000
30 Ramzan Khan 0303 35000 3000 32000
32 Rana Ali 0307 20000 1500 18500
----------------------------------------------------------------------------
total 80000 7500 72500
I am using Laravel 5 and HTML, Bootstrap. I need this result in Laravel 5. I shall be really thankful if someone help me to solve my problem.
Thanks
Waseem
This is not at all a Laravel question. It's a general SQL question.
Something like this:
SELECT nd, Name, FatherName, Cell#, AdvanceAmount as Advance,
(SELECT SUM(Amount) FROM CommitteeTables WHERE CommitteeTables.nd=Custoemr.nd) as Amount, Advance-Balance AS Balance
FROM Customer;
I'm not entirely sure that's correct but you can try it and fix any errors. As Bogdan suggests you should try something first then come back here with any problems that you have.
I am trying clean up this employee volunteer data. There is no way to track if employee already is registered volunteer so he can sign up as new volunteer and will get a new VOLUNTEER_ID. I have a data feeding into where i can tie each VOLUNTEER_ID to its EMP_ID. The volunteer data needs to be cleaned up so we can figure out how the employee moved from a volunteer_level to another and when.
The business logic is that, when there is a overlaping dates, we give the highest level to the employee for the timeframe of between start_date and end_date.
I posted a Input sample of data and what the output should be.
Is it possible to do this a PIG script ? Can someone please help me
INPUT:
EMP_ID VOLUNTEER_ID V_LEVEL STATUS START_DATE END_DATE
10001 100 1 A 1/1/2006 12/31/2007
10001 200 1 A 5/1/2006
10001 100 1 A 1/1/2008
10001 300 3 P 3/1/2008 3/1/2008
10001 300 3 A 3/2/2008 12/1/2008
10001 1001 2 A 5/1/2008 6/30/2008
10001 1001 3 A 7/1/2008
10001 300 2 A 12/2/2008
OUTPUT NEEDED:( VOLUNTEER_ID is not needed in output but adding below to show which ID was selected for output and which did not)
EMP_ID VOLUNTEER_ID V_LEVEL STATUS START_DATE END_DATE
10001 100 1 A 1/1/2006 12/31/2007
10001 300 3 P 3/1/2008 3/1/2008
10001 300 3 A 3/2/2008 12/1/2008
10001 1001 2 A 5/1/2008 6/30/2008
10001 1001 3 A 7/1/2008
It seems like you want the row in your data with the earliest start date for each V_LEVEL, STATUS, EMP_ID, and VOLUNTEER_ID
First we add a unix time column and then find the min for that column (this is in the latest version of pig so you may need to update your version).
data_with_unix = foreach data generate EMP_ID, VOLUNTEER_ID, V_LEVEL, STATUS, START_DATE, END_DATE, ToUnixTime((datetime)START_DATE) as unix_time;
grp = group data_with_unix by (EMP_ID, VOLUNTEER_ID, V_LEVEL, STATUS);
max_date = foreach grp generate group, MIN(data_with_unix.unix_time);
Then join the start and end date back into your dataset since there it doesn't look like there is currently a way to convert unix time back to date.
I have 3 tables; COMPANY, TRAINING TICKET and TEST.
COMPANY table:
COMPANY CODE | COMPANY NAME
192 ABC ENTERPRISE
299 XYZ ENTERPRISE
TRAINING TICKET table:
TICKET ID | COMPANY CODE | START DATE
2900 192 2015-02-02
3939 192 2015-03-03
4399 299 2015-03-02
TEST SESSION table:
TEST CODE | TICKET ID | COMPANY CODE | CERTIFIED
1221 2900 192 YES
2821 3939 192 NULL
3922 4399 299 YES
I need something like this:
C. CODE | COMPANY NAME | 1ST START DATE | TRAINING TICKET TOTAL | CERTIFIED TOTAL
192 ABC ENTERPRISE 2015-02-02 2 1
299 XYZ ENTERPRISE 2015-03-02 1 1
Its possible?
My Sql instruction is:
Select *, count(TICKET.CCODE) AS TICKET_TOTAL, count(TEST.CODE) AS CERT_TOTAL
from TICKET
Inner Join COMPANY on TICKET.CCODE = COMPANY.CCODE
Inner Join TEST on COMPANY.CCODE = TEST.CCODE
Group by (TICKET.CCODE),(TEST.CCODE)
Order by TICKET_TOTAL DESC
but both counts are always equals (same result for TICKET_TOTAL and CERT_TOTAL) and the sums are wrong - the result is TICKET_TOTAL = 21 and CERT_TOTAL = 28, but I got 523 - for TOP 1 company.
I got the answer:
Select COMPANY.CODE, COMPANY.NAME,
MIN(TICKET.STARTDATE), count(TICKET.TICKETID) AS TICKET_TOTAL,
count(TEST.CERTIFIED) AS CERT_TOTAL
from COMPANY
INNER JOIN TICKET ON COMPANY.CODE = TICKET.CCODE
LEFT JOIN TEST ON TICKET.TICKETID = TEST.TICKET
Group by (TICKET.CCODE)
ORDER BY TICKET_TOTAL DESC
1- Reorder and star the instruction from COMPANY TABLE
2- MIN(TICKET.STARTDATE) to got the First Start Date (Use MAX to got the Last Start Date if necessary)
3- Change Inner Join to Left Join (because some companies have a ticket on ticket table but does not have a test on test table)
Hope this can help someone in the future!