简体   繁体   中英

SQL query / SQL Reporting Services

Been rattling my brain for a while and I could not get pass how to do the SQL query that will show the relationship/connections between my two tables.

I'm working on an IT equipment inventory program. I have two tables;

SELECT serial_number, model, ship_dat, status FROM items_list

SELECT item_serial, connected-to_serial FROM connections

All items like desktops, laptops, monitors, etc are on the items_list table. To track down the relationship/connections of the items, I created the connections table. IE, Monitor with serial_number=Screen#1 is connected to a Desktop with serial_number=Serial#1. It works ok with my Window Form application because I used a datagridview control to list all devices simple SQL query.

However, when trying to show the relationship/connection on SQL Reports I've ran out of ideas how to do it. I'm aiming to get the report look like below or something along the lines. I just need to show the connections between the items.

Thank you

You should be able to do this with a table in SSRS if that is what you are using. The query you would need to drive the table of all related items would be:

SELECT item_serial, connected-to_serial, mainItem.*, connectedItem.*
FROM connections
    INNER JOIN items_list mainItem ON connections.item_serial = items_list.serial_number
    INNER JOIN items_list connectedItem ON connections.connected-to_serial = connectedItem.serial_number 

You can of course tailor the SELECT statement to your needs, mainItem.* and connectedItem.* will not give you the most descriptive column names. Using column aliases (found under column_alias here ) you can give a more descriptive name to each column.

From here you should be able to use a table and create a row group on the main item (either name or serial number) to get the type of look you are looking to achieve here. I believe the Report Wizard actually has most of the functionality you are looking for and should handle the bulk of this. You may have to move some of the cells around to get the look you are going for though.

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