Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Would like help with SQL Query #167

Open
mvoity opened this issue Feb 8, 2022 · 4 comments
Open

Would like help with SQL Query #167

mvoity opened this issue Feb 8, 2022 · 4 comments

Comments

@mvoity
Copy link

mvoity commented Feb 8, 2022

I am still using NetDot and Love it.

I am working on a SQL query to run against the database that will hit a couple tables to provide a report for our cost accounting group.

Here is my original SQL, it works, but is missing data –

select
d.sysname, d.sysdescription, d.last_updated, d.date_installed, a.serial_number, a.product_id, a.inventory_number
from device d, asset a
where d.asset_id = a.id
AND a.inventory_number like 'a%';

The problem is that in a device, there are modules that’s have assets that has an inventory number and that data is not matching up

Is there any way you can help me create a SQL script that will get the missing data?

Here is my most recent SQL but I am still striking out, getting duplicate data and missing data.

select
d.sysname, d.syslocation, d.last_updated, d.date_installed, d.asset_id,a.serial_number, a.inventory_number
from device d, asset a, devicemodule m, devicemodule e
where m.asset_id = d.asset_id AND m.device = d.id and d.asset_id = a.id and a.id = e.asset_id
AND a.inventory_number like 'A%'

My end goal is to get the following fields -
d.sysname, d.syslocation, d.last_updated, d.date_installed, d.asset_id,a.serial_number, a.inventory_number

Any guidance you can give me would be very much appreciated.

Thanks again,

-Mike
_
Michael T. Voity | Network Engineer | Telecommunications & Network Services| Enterprise Technology Services | The University of Vermont |

@nicolatron
Copy link
Contributor

nicolatron commented Feb 8, 2022

Not sure this is what you want, but to me when doing complex queries, using join helps me not getting crazy.
And playing with inner/outer left/right join can help get more or less stuff.

Something in the line of this...

SELECT
d.sysname, d.syslocation, d.last_updated, d.date_installed, d.asset_id,a.serial_number, a.inventory_number
FROM device d
JOIN asset a on d.asset_id = a.id
where a.inventory_number like 'A%';

@mvoity
Copy link
Author

mvoity commented Feb 8, 2022

Nicolás,

Thanks for your quick response, I really do appreciate it.

The Join you provided didn't provide any more results than the original query.

I think the Join I need has something to do with the devicemodule table, asset table and then device table.

my sql skills are sub par, any idea on how to do that join?

Thanks again for looking and your help.

-Mike

@nicolatron
Copy link
Contributor

Hello Mike,

Another shot...

SELECT device.sysname, device.syslocation, device.last_updated, device.date_installed, device.asset_id, asset.serial_number, product.name, inventory_number
FROM device
LEFT JOIN asset on device.asset_id = asset.id
LEFT JOIN devicemodule on devicemodule.asset_id = asset.id
JOIN product on asset.product_id = product.id
group by device.id order by device.id, date_installed;

@mvoity
Copy link
Author

mvoity commented Feb 8, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants