简体   繁体   中英

How to pull required data from table the way Crystal is pulling it?

I have a view set up like the below table, which is pulling data from multiple other tables using JOINS. Basically I'm trying to replicate a Crystal Report that breaks up the data below into Job # - Weekly (hrs) - TotalToDate(hrs) - Budget(hrs)

And this is broken up per department. The way the report does it is it'll display the hours for the last week, then the total hours to date then the budgeted hours set for that department. 图片供参考

Table doesn't reflect above - just an example of what DB table looks like.

    +-----------+------------+---------------+--------+---------------------+
    | Job       |  Work_Date | Work_Center   | Est_Total_Hrs | Act_Run_Hrs  |
    +-----------+------------+---------------+--------+------+--------------+
    |      5666 | 2014-02-23 | SURFACE       |     155       |      5       | 
    |      5666 | 2014-02-16 | SURFACE       |     155       |      3       |      
    |      5666 | 2014-02-23 | DESIGN        |     200       |      6       |      
    |      5666 | 2014-02-16 | DESIGN        |     200       |      4       |       
    |      5666 | 2014-02-23 | SURFACE       |     150       |      2       |      
    |      5666 | 2014-02-16 | SURFACE       |     150       |      2       |       
    |      5666 | 2014-02-23 | DESIGN        |     300       |      8       |       
    +-----------+------------+---------------+---------------+--------------+

Also, theres a lot of different job numbers, and when I pull up more than 1 job in Crystal it'll show the report like the picture above but with all jobs I want to retrieve.

How would I go about pulling this data so it shows up the same way in the Crystal Report? I want to create a view that looks the same. Is there a way to see how Crystal does it? When I click "Show Query" it shows me the below query which I had to re-write a little bit for it to work in SQL Server and in Adminer.

Query I'm using to pull ALL data for all Jobs within an updated Work_Date in the last 90 days.

SELECT Job_Operation.Work_Center
    ,Job_Operation.Job_Operation
    ,Job_Operation_Time.Work_Date
    ,Job_Operation.Est_Total_Hrs
    ,Job_Operation_Time.Act_Run_Hrs
    ,Job_Operation_Time.Act_Setup_Hrs
    ,Job.Description
    ,Job_Operation_Time.Overtime_Hrs
    ,Job_Operation_Time.Act_Setup_Hrs
    ,Job.Job
    ,Job.Description
    ,Job_Operation_Time.Labor_Burden
    ,Job_Operation.Est_Setup_Labor
    ,Job_Operation.Est_Run_Labor
    ,Job_Operation.Est_Labor_Burden
    ,Job_Operation.Operation_Service
FROM Job AS Job 
LEFT OUTER JOIN Job_Operation AS Job_Operation ON Job.Job = Job_Operation.Job
LEFT OUTER JOIN Job_Operation_Time AS Job_Operation_Time ON Job_Operation.Job_Operation = Job_Operation_Time.Job_Operation
WHERE DATEDIFF(day, Work_Date, GETDATE()) < 90 ORDER BY Work_Date Desc

Crystal will take the data from a query and does its internal manipulation as per the design of the report, So if you need the table exactly as you view the report then along with the query in crystal report you need to make some changes.

Suggestions:

  1. Your report has only 6 columns but you query has more than 10 columns so you need to change the query so that it has only 6 columns.

  2. Report has data according to the week but query has hourly data so you need to write some functions in query so that you manage to get weekly data from hour data

  3. You said when you take more than 1 ID you get in the given format then in that case add some group by conditions to the resultant query so that all data is grouped. for eg if you need only one ID then group by ID so that there is only one record for a ID.

  4. Try adding some group by conditions some date formulas to get exact output

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM