Get data from 2 table options!

(5 posts) (2 voices)

Tags:

No tags yet.

  1. vannc, Member

    Dear Team,

    I am currently facing an issue with the solution for two views in the P&L report: "Management perspective" and "Accounting perspective".

    I need to implement two buttons. If I select the "Management perspective" button, the data should be retrieved from the table pl_report_management. Otherwise, if I select the other button, the data should come from the table pl_report_accounting. The default view should be pl_report_accounting.

    I consulted with ChatGPT and found a proposed solution:
    ------------------------------------------------------------
    DECLARE @sql NVARCHAR(MAX)
    SET @sql = '';
    EXEC sp_executesql @sql,
    N'@language NVARCHAR(3), @currencyType NVARCHAR(3), @priceFormat NVARCHAR(10), @exchange_rate DECIMAL(18,4), @filterDepartment NVARCHAR(MAX), @version NVARCHAR(MAX), @startDate DATE, @endDate DATE',
    @language, @currencyType, @priceFormat, @exchange_rate, @filterDepartment, @version, @startDate, @endDate
    ------------------------------------------------------------
    My code base of this demo: https://mydbr.com/demo/mydbr/report.php?r=378&m=1&h=4eab3635679eaa678f6dc0c289c197cee152ca6c&i=1

    However, I believe there might be a better approach. Would you assist me with this?

    Thank you, Team!

  2. myDBR Team, Key Master

    This is not really a MyDBR question, but rather a question about your own report.

    The approach to adopt depends on the structures of the data in the two tables and the amount of data you have. If the tables are similar to each other, you can, for example, create a view that shows the two tables as one, which would simplify the actual report. Another option is to retrieve the necessary data into a temporary table using separate queries and then proceed with the report using a common code.

    --
    myDBR Team

  3. vannc, Member

    Dear Team!

    Thanks team, the format of report is the same. But just need to change the first column, example in P&L report when click the account_code the drilldown the data of department in the same report. Or another case is just same report but get data from other table option. My desire is handle every report in just min procedure, as min as possible. But I try so hard did not solve problem yet :(. Would you please give me a report demo, or another more detail

    Thanks team!

  4. myDBR Team, Key Master

    Unfortunately, we cannot write your report for you. However, we do offer consultation services that you can utilize to get started.

    In the current example, you could create a view that contains data from both pl_report_management and pl_report_accounting, separating them with an extra column in the view. This would help you create a report that hides the complexity of dealing with multiple tables.

    In the report, you can then use that column to determine from which table the data comes. Similarly, you could pass the extra column to the linked reports.

    --
    myDBR Team

  5. vannc, Member

    Dear team!

    Thanks team for your advice :D

    Best regards:
    Vannc


Reply

You must log in to post.