Database view not limiting results
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2023 10:07 AM
I've created a simple view for reporting use in our data warehouse on the Hardware (alm_hardware) table. Only assets that are "In Use" should be in the view, but it's not limiting the assets and I can't figure out why (we aren't using life cycle yet). Can someone help me understand why the where clause isn't working? The view currently only has one table in it - Hardware. TIA!
View:
Results when clicking "Try it":
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2023 12:25 PM
Database views must consist of two or more tables joined together by a common field. You can self-join the hardware table and limit the records to only those in use like this:
Where clause on h2:
h1_sys_id=h2_sys_id&&h1_install_status=1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2023 01:27 PM
They don't have to consist of multiple tables as I am able to use a single table to verify the fields and data that I want in my view. I do still have three more tables to join.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2023 05:34 AM
This isn't SQL. If you're going to use the ServiceNow defined Database View functionality, then you have to follow the parameters by which it was designed to operate.
As demonstrated, my response clearly addressed your stated question. When asking for help from others, state your actual question for your use case.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2023 12:30 PM
It's only when you're connecting columns between tables that you need the single =, if you're using a boolean return value for filtering like you are here you'll need ==, as shown in my screenshots. I used the OOB incident_sla database view and filtered it so that only Incidents with a state of 'New' are returned.