Пожалуйста, попробуйте следующее. Выражение XPath проверяет именно то, что вам нужно.
SQL
-- DDL and sample data population, start
DECLARE @tbl TABLE
(
RecordId INT IDENTITY(10,1) PRIMARY KEY,
XmlData XML NOT NULL
);
INSERT INTO @tbl (XmlData)
VALUES (N'<?xml version="1.0" ?>
<DataObject>
<Objects>
<Object Name="FirstName" Value="John" />
<Object Name="LastName" Value="Smith" />
<Object Name="City" Value="Miami" />
<Object Name="State" Value="FL" />
<Object Name="Department" Value="HR" />
</Objects>
</DataObject>')
, (N'<?xml version="1.0" ?>
<DataObject>
<Objects>
<Object Name="FirstName" Value="Jane" />
<Object Name="LastName" Value="Doe" />
<Object Name="City" Value="Hollywood" />
<Object Name="State" Value="FL" />
<Object Name="Department" Value="Accounting" />
</Objects>
</DataObject>');
-- DDL and sample data population, end
DECLARE @Dept VARCHAR(30) = 'HR', @State CHAR(2) = 'FL';
SELECT RecordID
FROM @tbl
WHERE XMLData.exist('/DataObject/Objects[Object[@Name="State" and @Value=sql:variable("@State")]
and Object[@Name="Department" and @Value=sql:variable("@Dept")]]') = 1;
Вывод
+----------+
| RecordID |
+----------+
| 10 |
+----------+