Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Report Based On Multiple SQL Queries

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Report Based On Multiple SQL Queries

    This is more of a general question that I need a point in the right direction.

    I have a UX component with several Viewbox controls. Each viewbox control has it's own SQL query based on different unrelated tables. The UX basically acts as a summary page of the Viewbox info.

    I want to create a single report that will mimic the data on the summary page. So, I need a report that is based on multiple SQL queries that are coming from different tables and not joined in any way ... I need each Query displayed separately.
    Creating a report on a single query is easy but I don't know how, if it is even possible, to do it for multiple queries.

    Anybody have any idea?
    Alpha Anywhere v12.4.6.5.2 Build 8867-5691 IIS v10.0 on Windows Server 2019 Std in Hyper-V

    #2
    Do something like this:

    SELECT [ID]
    ,[Title]
    ,[Date]
    ,[Description]
    ,NULL AS [This]
    ,NULL AS [That]
    ,NULL AS [thisDate]
    ,NULL AS [otherDescription]
    FROM table1

    UNION ALL

    SELECT NULL AS [ID]
    ,NULL AS [Title]
    ,NULL AS [Date]
    ,NULL AS [Description]
    ,[This]
    ,[That]
    ,[thisDate]
    ,[otherDescription]
    FROM table2;

    If you have ChatGPT, you can input each of your queries for each viewbox into ChatGPT and say "make this one query showing all fields. Tables aren't related" and it'll do it for you.
    image.png

    Comment


      #3
      might be much faster (render time) to create a view with everything you need, should allow you to see the data returned is what you need before you get to building that report!
      NWCOPRO: Nuisance Wildlife Control Software My Application: http://www.nwcopro.com "Without forgetting, we would have no memory at all...now what was I saying?"

      Comment


        #4
        I agree with Charles. I'm not sure how long it'll take, but you might want to do as much as you can in the database. If it's a massive amount of data, you may even schedule something to update a table every x minutes and use slightly older data. It all depends on the amount of data and use case.

        Comment


          #5
          How slow are the queries ?
          It would be a shame to have to query everything again instead of combining the loaded data into one summary viewbox.
          Gregg
          https://paiza.io is a great site to test and share sql code

          Comment


            #6
            Thanks guys, I will look at creating a view. The queries are not large ... returning only the last record for 9 unique treatment units. Something like this:

            Code:
            *************************** WATER ************************
            SELECT     OutputWaterQaId,
                MachineDisplayName,
                MachineId,
                Day,
                Abs(DATEDIFF(day, GetDate(), Day)) AS ElapsedDays,
                PrimaryPhys,
                BackupPhys,
                Approved
            FROM QaOutputWater
            WHERE OutputWaterQaId IN (SELECT MAX(OutputWaterQaId) FROM QaOutputWater GROUP BY MachineId)  
            ORDER BY MachineId
            
            *************************** ENERGY ************************
            SELECT     OutputPlasticQaId,
                MachineDisplayName,
                MachineId,
                Day,
                Abs(DATEDIFF(day, GetDate(), Day)) AS ElapsedDays,
                PrimaryPhys,
                BackupPhys,
                Approved
            FROM QaOutputPlastic
            WHERE OutputPlasticQaId IN (SELECT MAX(OutputPlasticQaId) FROM QaOutputPlastic GROUP BY MachineId)  
            ORDER BY MachineId
            
            ​
            I don't have a ChatGPT account, maybe it's time
            Alpha Anywhere v12.4.6.5.2 Build 8867-5691 IIS v10.0 on Windows Server 2019 Std in Hyper-V

            Comment


              #7
              I haven't tried yet, but this (build 8806) suggests there is no need to make another call to the sql server.
              Getting the data from the various viewboxes into a state variable is relatively easy.

              Capture.png
              Gregg
              https://paiza.io is a great site to test and share sql code

              Comment


                #8
                If they are not joined in any way then why this " GROUP BY MachineId" - in both queries - the MachineID being used as an argument is the common join - you should be using the Nested SQL Query - query type in the Viewbox Builder. It's the most powerful part of the viewbox's data tools.
                Insanity: doing the same thing over and over again and expecting different results.
                Albert Einstein, (attributed)
                US (German-born) physicist (1879 - 1955)

                Comment


                  #9
                  Originally posted by madtowng View Post
                  I haven't tried yet, but this (build 8806) suggests there is no need to make another call to the sql server.
                  Getting the data from the various viewboxes into a state variable is relatively easy.

                  Capture.png
                  I am currently on build 8540 and I am very gun shy about updates. But this is definitely something I can look into when I do decide to update.
                  Thank Gregg.
                  Alpha Anywhere v12.4.6.5.2 Build 8867-5691 IIS v10.0 on Windows Server 2019 Std in Hyper-V

                  Comment


                    #10
                    Originally posted by peteconway View Post
                    If they are not joined in any way then why this " GROUP BY MachineId" - in both queries - the MachineID being used as an argument is the common join - you should be using the Nested SQL Query - query type in the Viewbox Builder. It's the most powerful part of the viewbox's data tools.
                    Hey Pete, nice to see you are still around

                    The reason for the GROUP BY MachineId is that the query will not return the last record for each MachineId if this is not included. See below.

                    This returns last record for each machine.

                    Query1.jpg

                    This does not return last record per machine, only the first last record it encounters.

                    Query2.jpg


                    To try and explain what is going on, there are 9 radiation treatment units at our centre. The Physics department performs various regular QA checks (output, energy, mechanical, etc) on each one of these treatment units.
                    Every type of QA check has it's own entry form which gets stores in its own SQL table.

                    This data is summarized on a UX component using a viewbox to perform the SQL query for each type of QA showing only the last QA that was performed. This works great! No problem in the UX component. See example below ...

                    Summary.jpg


                    Now I wanted to have a button to click and generate a report with the same summary information contained in the UX above.
                    The problem of course, is that the UX is based on several viewbox SQL queries and I don't see how to combine the data in the queries into a single query that I can use in a report.
                    So that is what I am struggling with. I can generate a single report for each case above, but that's not really what I'm looking for.




                    Alpha Anywhere v12.4.6.5.2 Build 8867-5691 IIS v10.0 on Windows Server 2019 Std in Hyper-V

                    Comment


                      #11
                      If this works in SQL you can easily create a view with it, but I agree that MachineId does look like the join field (at least with the 2 tables provided). If you want to provide all of the SQL Statements I can put them into a query for you real quick to try, then create a statement to create a view for you, or I can send you a Zoom link, and walk you through how I'd do it (Not to insult your intelligence by any means, I'm just helping from the lowest level. I haven't even spent the time learning ViewBoxes yet).

                      (SELECT OutputWaterQaId,
                      MachineDisplayName AS OutputWaterMachineDisplayName,
                      MachineId AS OutputWaterMachineId,
                      Day AS OutputWaterDay,
                      Abs(DATEDIFF(day, CURDATE(), Day)) AS OutputWaterElapsedDays,
                      PrimaryPhys AS OutputWaterPrimaryPhys,
                      BackupPhys AS OutputWaterBackupPhys,
                      Approved AS OutputWaterApproved
                      FROM QaOutputWater
                      WHERE OutputWaterQaId IN (SELECT MAX(OutputWaterQaId) FROM QaOutputWater GROUP BY MachineId)
                      )

                      UNION ALL

                      (SELECT OutputPlasticQaId,
                      MachineDisplayName AS OutputPlasticMachineDisplayName,
                      MachineId AS OutputPlasticMachineId,
                      Day AS OutputPlasticDay,
                      Abs(DATEDIFF(day, CURDATE(), Day)) AS OutputPlasticElapsedDays,
                      PrimaryPhys AS OutputPlasticPrimaryPhys,
                      BackupPhys AS OutputPlasticBackupPhys,
                      Approved AS OutputPlasticApproved
                      FROM QaOutputPlastic
                      WHERE OutputPlasticQaId IN (SELECT MAX(OutputPlasticQaId) FROM QaOutputPlastic GROUP BY MachineId)
                      )

                      -- Unsure of how you want to set this up, but MachineId may need/not need to be prefaced with Outupt'type'MachineId
                      -- ORDER BY MachineId;

                      Comment


                        #12
                        I understand being shy about updates.
                        You can "cheat" by testing with Community edition.
                        I haven't tested the code below with your data, but if it doesn't work, I'm sure the adjustments will be simple.
                        I just did a last check. It looks like your viewboxes have 3 different formats.
                        I adjusted the code to combine the first 2 viewboxes.
                        Let me know what you think about the other viewboxes.
                        Code:
                        var vb1PTR = {dialog.object}.getControl('vb1');
                        var vb2PTR = {dialog.object}.getControl('vb2');
                        ​
                        var reportArray  = vb1PTR.data;
                        reportArray.push( vb2PTR.data);
                        {dialog.object}.stateInfo['reportArray'] = reportArray;
                        ​​​​​​​
                        Gregg
                        https://paiza.io is a great site to test and share sql code

                        Comment


                          #13
                          Originally posted by Russell Craycraft View Post
                          ...I can send you a Zoom link, and walk you through how I'd do it (Not to insult your intelligence by any means...)​
                          You can't insult what I don't have .. haha! I appreciate all the help I can get.

                          I tried to use your suggestion with the UNION ALL previously but it doesn't quite get what I want. It's close but it ends up combining the data from the second query into the same field column names as the first query.​

                          Union All.jpg

                          I've attached the viewbox queries I'm trying to use on a single report.
                          Attached Files
                          Alpha Anywhere v12.4.6.5.2 Build 8867-5691 IIS v10.0 on Windows Server 2019 Std in Hyper-V

                          Comment


                            #14
                            The viewbox is a very powerful tool, with some great examples. Have a look at the home tab of a newly created viewbox. Near the bottom there is a hyperlink to load sample viewbox. From the list that comes up choose the Advanced: List of orders..... This will create the data and layout of a very powerful viewbox, with examples of expand and collapse of sections as well print an HTML report of the viewbox layout without any callbacks for the data. I am sure with a little work the data from each of your viewboxes can be collected and linked into one in the same manner

                            Comment


                              #15
                              You might want to add another column to each part of the union all query, in this case I would add 'QaOutputWater' as 'fromtable' to the first query, and 'QaOutputPlastic' as 'fromtable' to the second query.
                              This obviously gives you a way to determine where it's from.
                              Gregg
                              https://paiza.io is a great site to test and share sql code

                              Comment

                              Working...
                              X