This post is all about how to use namespace (xmlns) with xquery.
declare @emp xml
set @emp = '<Employees xmlns="http://www.xml.com/XSD">
<Employee>
<Code>1</Code>
<FirstName>Nishant</FirstName>
</Employee>
<Employee>
<Code>2</Code>
<FirstName>Kavita</FirstName>
</Employee>
</Employees>'
declare @totalemp int
set @totalemp = cast(cast(@emp.query('declare namespace X="http://www.xml.com/XSD";
count(/X:Employees/X:Employee/X:Code)') as varchar) as int)
select @totalemp
Sometimes simple example helps a lot.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment