简体   繁体   中英

Display data from three SQL tables in a dataset using a parameter field

I am creating a SQL report with below queries from 3 different tables in one single dataset. And created a parameter name as @type. When i run the query it shows only the data from the first query in the report and no data coming from the second query.

Also in the Parameter @type Drop Down i gave names as Network Printer and Local Printer. For both its showing only the Network printers data.

Kindly help me on how do i achieve the complete data from both reports, and when selected the network Printer it should show network printers and when selected Local Printers it should show local printers.

SELECT V_GS_NETWORKPRINTERS0.ResourceID, DEV.Netbios_Name0 AS Netbios_Name, PrinterQueue0 AS PrinterName, PrintServer0 AS PrinterServer, 
PrinterLocation0 AS PrinterLocation, PrinterDriver0 AS PrinterDriver, DateInventoried0 AS Timestamp, 'Network Printer' AS Type FROM V_GS_NETWORKPRINTERS0
LEFT JOIN v_R_System_Valid DEV ON DEV.ResourceID = V_GS_NETWORKPRINTERS0.ResourceID ORDER BY DEV.Netbios_Name0

SELECT ResourceID, SystemName0 AS Netbios_Name, Caption0 AS PrinterName, SystemName0 AS PrinterServer, SystemName0 AS PrinterLocation,
DriverName0 AS PrinterDriver, TimeStamp AS Timestamp, 'Local Printer' AS Type FROM V_GS_PRINTER_DEVICE
ORDER BY PrinterName
SELECT * FROM (SELECT V_GS_NETWORKPRINTERS0.ResourceID, DEV.Netbios_Name0 AS Netbios_Name, PrinterQueue0 AS PrinterName, PrintServer0 AS PrinterServer, 
PrinterLocation0 AS PrinterLocation, PrinterDriver0 AS PrinterDriver, DateInventoried0 AS Timestamp, 'Network Printer' AS Type FROM V_GS_NETWORKPRINTERS0
LEFT JOIN v_R_System_Valid DEV ON DEV.ResourceID = V_GS_NETWORKPRINTERS0.ResourceID ORDER BY DEV.Netbios_Name0

UNION ALL

SELECT ResourceID, SystemName0 AS Netbios_Name, Caption0 AS PrinterName, SystemName0 AS PrinterServer, SystemName0 AS PrinterLocation,
DriverName0 AS PrinterDriver, TimeStamp AS Timestamp, 'Local Printer' AS Type FROM V_GS_PRINTER_DEVICE) as X
WHERE X.Type=@type

Try this. The "union all" joins the data set together, the top select statement treats the union all subquery as one dataset, then you add the parameter to the Where clause of the new union dataset.

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