in Education by
Select * from OPENQUERY (PORTAL, ''SELECT st.last AS "Last Name", st.first AS "First Name", ct.DeviceName, SUM (ct.PageCount) AS "Count", pm.TotalPerPage FROM printer_stats.Counts ct INNER JOIN dv.staff st on st.id = ct.UserID LEFT JOIN network_map.PrintersToDevices ptd ON ptd.DeviceID = ct.DeviceID LEFT JOIN network_map.PrinterModels pm ON ptd.PrinterID = pm.PrinterID WHERE ct.UserID = "'+@UserID+'" and ct.PageCount > 0 and ct.Date >= "'+@AcademicYTD+'" UNION SELECT stu.last_name AS "Last Namae", stu.first_name AS "First Name", ct.DeviceName,SUM(ct.PageCount) AS "Count", pm.TotalPerPage FROM printer_stats.Counts ct INNER JOIN dv.student stu on stu.username = ct.Username LEFT JOIN network_map.PrintersToDevices ptd ON ptd.DeviceID = ct.DeviceID LEFT JOIN network_map.PrinterModels pm ON ptd.PrinterID = pm.PrinterID WHERE ct.UserID = "'+@UserID+'" and ct.PageCount > 0 and ct.Date >= "'+@AcademicYTD+'" GROUP BY ct.DeviceName ORDER BY 4 DESC'') I get results like this: Last Name First Name DeviceName Count TotalPerPage Stewart Jesse BG-LMC-HP4100-01 39 0.0287581 Stewart Jesse BG-LMC-HP4100-02 9 0.0287581 Stewart Jesse BG-903-RI4210 2 0.013341 Stewart Jesse BG-218-HP4000 1 0.013341 NULL NULL NULL NULL NULL I don't want the last row of all NULLS. I know they are coming from the first SELECT for Staff since there should be no matching rows: The user is a Student, so there wouldn't be a match. I need to know how to only show rows with data in all fields. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
If you know what part of your UNION is providing the Null-row, you should first look at it, ensure that it returns what you want and fix your problem there. However, if you're otherwise satisfied that the query is as it should be, you can always do a hack with an EXCEPT SELECT NULL-construction: (I've included surrounding lines for reference) ... WHERE ct.UserID = "'+@UserID+'" and ct.PageCount > 0 and ct.Date >= "'+@AcademicYTD+'" EXCEPT SELECT NULL AS "Last Name", NULL AS "First Name", NULL as DeviceName, NULL AS "Count", NULL AS TotalPerPage GROUP BY ct.DeviceName ORDER BY 4 DESC'')

Related questions

0 votes
    I want to use python to connect to a MySQL database, how can I do that? Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    I have a query like this SELECT member_Id , PERIOD_DIFF( DATE_FORMAT(now(),'%Y%m'), DATE_FORMAT( ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 4, 2022 in Education by JackTerrance
0 votes
    I have a .sql file with an export from phpMyAdmin. I want to import it into a different server using the ... create a database first? Select the correct answer from above options...
asked Jan 26, 2022 in Education by JackTerrance
0 votes
    This one has been bugging me for a while now. Is there a way I can stop Intellj IDEA from ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 24, 2022 in Education by JackTerrance
0 votes
    I'm attempting to copy my MySQL database from an Amazon EC2 to an RDS: I successfully did a mysqldump of ... easy question. Thoughts? Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    is there an easy way to not draw this points in my lines? I don't know why this points are ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    I have a big table which contains about 100 million records in MySQL. I want to read all the ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Aug 1, 2022 in Education by JackTerrance
0 votes
    I get an error stating that there is incorrect syntax near the key word INNER. I wish to delete ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 1, 2022 in Education by JackTerrance
0 votes
    I get an error stating that there is incorrect syntax near the key word INNER. I wish to delete ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    How do I see which version of Swift I'm using?...
asked Mar 9, 2021 in Technology by JackTerrance
0 votes
    The Cookies Preferences box that always appears in the bottom right hand corner of the dataplatform.ibm.com ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    How to set same number 'priority' with one query for Mercedes. +--------------------- ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    My goal is to merge tables from different schema into one single schema so I would like to execute this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    How to enable inno-db support on installed instance of MySql? I have installed mysql-5.0.67-win32. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 23, 2022 in Education by JackTerrance
0 votes
    In my database I have some records where I am sorting by a column that contains identical values: | ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 27, 2022 in Education by JackTerrance
...