Subject:SQLXML and Subquery Author:Jasbir Luthera Date:04 Apr 2007 01:50 PM
I am trying to do a subquery (which returns exactly one row and one column) to get the value of an attribute, it doesn't work - no error messages:
SELECT XMLELEMENT(name "site",
XMLELEMENT(name "db_id", XMLATTRIBUTES('1-1-1' AS "attr"), t.id),
XMLELEMENT(name "name",
XMLATTRIBUTES((SELECT c.site_id
FROM site c
WHERE c.status = 'active'
AND c.location = 'us'
AND c.state = 'ca') AS "site_id"), t.site_name)
)
FROM plants p
PROBLEM: the site_name element should have an attribute called site_id from the respective subquery. See below for subquery results.
-----------------
For subquery:
SELECT c.site_id
FROM site c
WHERE c.status = 'active'
AND c.location = 'us'
AND c.state = 'ca'