Why is a spatial view returning empty or null records when field has a domain?

252
5
Jump to solution
04-08-2019 11:32 AM
Highlighted
New Contributor II

I'm attempting to create a spatial view between a feature class (wHydrant) and a related table (wHydrant_Maint).  I can successfully create views by querying every field in the Hydrant_Maint table, except one (Maint_Activity).  The only difference from the other fields is that this Maint_Activity field has a domain.  Any attempt to create a view with a WHERE clause on this field will return an empty view with no records returned.  When querying other fields, but including this field in the selection, all the results in this field return as null, even though there are in fact entries.  Here is my SQL statement that returns all NULL records in the Maint_Activity field:

SELECT h.OBJECTID, h.FACILITYID, h.SHAPE, r.Hydrant_ID, r.MAINT_ACTIVITY, r.MaintDate, r.GlobalID

FROM wHydrant h

JOIN wHydrant_Maint r

ON h.FACILITYID = r.Hydrant_ID

WHERE r.MaintDate >= '2014' AND r.MaintDate <= '2015'

The following returns an empty table view:

SELECT h.OBJECTID, h.FACILITYID, h.SHAPE, r.Hydrant_ID, r.MAINT_ACTIVITY, r.MaintDate, r.GlobalID
FROM wHydrant h
JOIN wHydrant_Maint r
ON h.FACILITYID = r.Hydrant_ID
WHERE r.MAINT_ACTIVITY = 'Flushed'

Do I need to adjust my syntax to account for a domained field?  Also, the code and description for the domain match, in case you're thinking I should query the code for 'Flushed'.  

Tags (3)
Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
MVP Regular Contributor

Is the data Versioned? Maybe you need to perform a Compress, to push edits from the a- & d- Tables into the Business Table (base Table).

Or, create the Spatial View based on the Versioned View of that feature class.

View solution in original post

5 Replies
Highlighted
Esri Frequent Contributor

I am not sure that you can add domains (as you see them in a client) to the spatial view as they are specific to advanced geodatabase functionality; https://desktop.arcgis.com/en/arcmap/latest/manage-data/geodatabases/registering-a-table-with-the-ge... 

You may be able to do it if you specify the domain value(i.e. - 0,1,2,3,4,5, etc.) that is stored in the GDB base table.

--- George T.
Highlighted
New Contributor II

The code value and the description are the same for this domain.  We did not use numeric codes in this instance.  However, I went into SSMS to view the wHydrant_Maint table records and all of the MAINT_ACTIVITY records are NULL.  Yet when the table is viewed in Arc I see all the entries.  So if SQL doesn't see the entries, how am I supposed to query them in SQL?  Also, I noticed that all the fields with domains are NULL when viewed in SSMS, BUT there is also a "NOTES" field, a text field with no domain, that is also all NULL in SQL.  

Reply
0 Kudos
Highlighted
MVP Regular Contributor

Is the data Versioned? Maybe you need to perform a Compress, to push edits from the a- & d- Tables into the Business Table (base Table).

Or, create the Spatial View based on the Versioned View of that feature class.

View solution in original post

Highlighted
New Contributor II

The data is registered as versioned.  When I view the System View table in SQL I can now see my entries, whereas all entries are NULL when I view the base table.  I will test querying this table and report back my results.

Reply
0 Kudos
Highlighted
New Contributor II

The queries in my original question are actually correct and were returning the correct results as the MAINT_ACTIVITY field in the base table was actually all NULL records.  Since the table was registered as versioned, the records I wanted to query were in the Views folder of SSMS.  So the following query returned the results that I have been looking for via a spatial view:

SELECT h.OBJECTID, h.FACILITYID, h.SHAPE, r.Hydrant_ID, r.MAINT_ACTIVITY, r.MaintDate, r.GlobalID
FROM wHydrant h
JOIN wHydrant_Maint_evw r
ON h.FACILITYID = r.Hydrant_ID
WHERE (r.MaintDate >= '2014' AND r.MaintDate <= '2015') AND r.MAINT_ACTIVITY = 'Flushed'

Thank you George & Asrujit for guiding me to the base & view tables in SSMS.