Showing posts with label xml. Show all posts
Showing posts with label xml. Show all posts

Friday, March 30, 2012

Query XML type with values from another XML type

Hi - I'm using SQL Server 2005, and I have a view with an XML data type column. I would like to write a stored proc that takes an XML data type as a parameter and return the rows from the view that match the columns in the parameter.

At this point, I'm just trying to get the syntax correct, so I started with some simple queries. Below are the queries:

declare @.params xml

declare @.view xml

set @.params = '<HierarchyTypes>

<HierarchyType hierarchyTypeId="4" />

<HierarchyType hierarchyTypeId="5" />

</HierarchyTypes>'

set @.view = '<HierarchyTypes>

<HierarchyType hierarchyTypeId="4" otherProp = "1"/>

<HierarchyType hierarchyTypeId="5" otherProp = "2"/>

<HierarchyType hierarchyTypeId="6" otherProp = "3"/>

<HierarchyType hierarchyTypeId="7" otherProp = "4"/>

</HierarchyTypes>'

SELECT T.c.query('.') AS result

FROM @.view.nodes('/HierarchyTypes/HierarchyType') T(c)

I would like to get the nodes from @.view where @.view.hierarchyTypeId = @.params.hierarchyTypeId. This should be pretty simple, but I'm missing it...

Any thoughts are appreciated!

Thanks,

Phil

It sounds like you are trying to join view and params to get a results set which has one matching node per row. If that is the case, the below query should be doing what you are looking for. If you want to return a single xml fragment, a different technique would have to be used.

In the query below, we iterate over the HierarchyType nodes of both @.view and @.params, project the values of the hierarchyTypeId attributes as integers using the the value() function, verify that they match, and the return the @.param node that matches.

declare @.params xml
declare @.view xml

set @.params = '<HierarchyTypes>
<HierarchyType hierarchyTypeId="4" />
<HierarchyType hierarchyTypeId="5" />
</HierarchyTypes>'

set @.view = '<HierarchyTypes>
<HierarchyType hierarchyTypeId="4" otherProp = "1"/>
<HierarchyType hierarchyTypeId="5" otherProp = "2"/>
<HierarchyType hierarchyTypeId="6" otherProp = "3"/>
<HierarchyType hierarchyTypeId="7" otherProp = "4"/>
</HierarchyTypes>'

SELECT T.c.query('.') AS result
FROM @.view.nodes('/HierarchyTypes/HierarchyType') T(c),

@.params.nodes('/HierarchyTypes/HierarchyType') P(c)
WHERE T.c.value('@.hierarchyTypeId', 'int') = P.c.value('@.hierarchyTypeId', 'int')

|||

Hi Todd - this is very close to what I need. The only other wrinkle is that I'm trying to select all of the columns from the view (not just the hierarchyTypeId). The view has an XML column called HierarchyTypes, and I want to use that column in my 'join criteria'. And I'd like to do this in a stored proc.

CREATE PROCEDURE [dbo].[CodeHierarchy_SearchHierarchy]
@.codeTypes xml = NULL
AS
BEGIN
SET NOCOUNT ON;
SELECT v.nodeId,
v.parentNodeId,
v.HierarchyTypes
FROM VLinkedCodeHierarchies as v
WHERE /* hierarchyTypes in @.codeTypes are also in v.HierarchyTypes */

At this point, I also require that the return is NOT XML.

Thanks,

Phil

|||

So it sounds like you have a table or a view that has a few relational columns, and 1 xml column. And then you want to join it with an XML fragment.

Is that correct?

If so, then you can modify the query to use CROSS APPLY. In the example I create a test table which has an xml column, fill it with data and then join it with the fragment, projecting the relevant relational columns and xml data. You could then wrap it in a stored procedure or user defined function as needed.

(I CROSS APPLY the vTest table with nodes() function so that I get the nodes for the current row.)

declare @.params xml

drop table vTest
Create table vTest(
id int,
val xml
)


insert into vTest (id, val) values (1,'<HierarchyTypes>
<HierarchyType hierarchyTypeId="4" otherProp = "1"/>
<HierarchyType hierarchyTypeId="5" otherProp = "2"/>
<HierarchyType hierarchyTypeId="6" otherProp = "3"/>
<HierarchyType hierarchyTypeId="7" otherProp = "4"/>
</HierarchyTypes>')


insert into vTest (id, val) values (2,'<HierarchyTypes>
<HierarchyType hierarchyTypeId="8" otherProp = "1"/>
<HierarchyType hierarchyTypeId="9" otherProp = "2"/>
<HierarchyType hierarchyTypeId="10" otherProp = "3"/>
<HierarchyType hierarchyTypeId="11" otherProp = "4"/>
</HierarchyTypes>')


set @.params = '<HierarchyTypes>
<HierarchyType hierarchyTypeId="4" />
<HierarchyType hierarchyTypeId="5" />
<HierarchyType hierarchyTypeId="11" />
</HierarchyTypes>'

SELECT vTable.Id,
xVal.c.value('@.hierarchyTypeId', 'int') as hierarchyTypeId,
xVal.c.value('@.otherProp', 'int') as otherProp,
xVal.c.query('.') as MatchingFragment

FROM @.params.nodes('/HierarchyTypes/HierarchyType') P(c),
vTest as vTable CROSS APPLY vTable.Val.nodes('/HierarchyTypes/HierarchyType') xVal(c)
WHERE xVal.c.value('@.hierarchyTypeId', 'int') = P.c.value('@.hierarchyTypeId', 'int')

If you dont want to Join the parameter fragment and the table, but just want to check that for each row it's xml column has some data in common with the parameter fragment, then you could change the query to use an EXISTS.

|||

Hi Todd - thanks again for the excellent reply. I actually want to make sure that the rows returned have data in common with the XML fragment.

Ideally, I would like to have 3 options:

1) View column has some data from XML fragement

2) View column has all data from XML fragment, but could have more.

3) View column has ONLY data from XML fragement.

I can accomplish #1 above using a SELECT DISTINCT, but I don't think that's the most optimum.

Where are some good resources to educate myself on this?

Thanks!

Phil

|||

Here is where you can find the the basics of XQuery and the T-SQL functions that support it:
http://msdn2.microsoft.com/en-us/library/ms190262.aspx

The current w3c resources:
http://www.w3.org/TR/xquery/

T-SQL Reference:
http://msdn2.microsoft.com/en-us/library/ms189826.aspx

And there are probably a number of tutorials that would discuss the differences of when to use a DISTINCT vs EXISTS vs CROSS APPLY.

Query xml field in Query Plan DMV

I anot expertin XML and need to query a value in the field "query_plan" of
the "sys.dm_exec_query_plan" DMV. The value I is the whether queries has
Parallelism value more than 0. I remeber have seen something like
sys.dm_exec_query_plan.query_plan.value ('declare namespace.......
Is there in BOL a chapter on how querying special SQL xml schemas ?
Thanks in advanceHello eliassal,
You could query the XML column in the DMV as any other XML column in SQL by
using the XQuery.
For example, I use this Statement to query the query_Plan:
select query_plan.query('declare namespace
showplan="http://schemas.microsoft.com/sqlserver/2004/07/showplan";
/showplan:ShowPlanXML/showplan:BatchSequence/showplan:Batch') from
sys.dm_exec_query_plan(<my plan handle id> )
For more detailed information about how to query the XML date using XQuery,
please refer this article:
XQuery Against the xml Data Type
http://msdn2.microsoft.com/en-us/library/ms189075.aspx
For more detailed information about the schema of the query_plan, pleaser
refer this article:
sys.dm_exec_query_plan
http://msdn2.microsoft.com/en-us/ms189747.aspx
http://schemas.microsoft.com/sqlserver/
Hope this will be helpful!
Sincerely,
Wei Lu
Microsoft Online Community Support
========================================
==========
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscript...ault.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscript...t/default.aspx.
========================================
==========
(This posting is provided "AS IS", with no warranties, and confers no
rights.)|||So many thanks, I tried so many times, so many syntaxes to work with the
"RelOp" element without success
In the sql schemq it is defined as follows :
<xsd:element name="RelOp" type="shp:RelOpType" />
<xsd:element name="ParameterList" type="shp:ColumnReferenceListType"
minOccurs="0" maxOccurs="1" />
As I said yesterday, I understood in a sql article that if the
max(...RelOp/@.parelle.....) > 0 gives us an idea if the query would be
paralleize.
I am deserate!!!HELP :-)
Thanks again
"Wei Lu [MSFT]" wrote:

> Hello eliassal,
> You could query the XML column in the DMV as any other XML column in SQL b
y
> using the XQuery.
> For example, I use this Statement to query the query_Plan:
> select query_plan.query('declare namespace
> showplan="http://schemas.microsoft.com/sqlserver/2004/07/showplan";
> /showplan:ShowPlanXML/showplan:BatchSequence/showplan:Batch') from
> sys.dm_exec_query_plan(<my plan handle id> )
> For more detailed information about how to query the XML date using XQuery
,
> please refer this article:
> XQuery Against the xml Data Type
> http://msdn2.microsoft.com/en-us/library/ms189075.aspx
> For more detailed information about the schema of the query_plan, pleaser
> refer this article:
> sys.dm_exec_query_plan
> http://msdn2.microsoft.com/en-us/ms189747.aspx
> http://schemas.microsoft.com/sqlserver/
> Hope this will be helpful!
> Sincerely,
> Wei Lu
> Microsoft Online Community Support
> ========================================
==========
> Get notification to my posts through email? Please refer to
> l]
> ications.
> Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the community or a Microsoft Support
> Engineer within 1 business day is acceptable. Please note that each follow
> up response may take approximately 2 business days as the support
> professional working with you may need further investigation to reach the
> most efficient resolution. The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions or complex
> project analysis and dump analysis issues. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by contacting
> Microsoft Customer Support Services (CSS) at
> [url]http://msdn.microsoft.com/subscriptions/support/default.aspx." target="_blank">http://msdn.microsoft.com/subscript...t/default.aspx.
> ========================================
==========
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
>
>|||Hello Eliassal,
I found that article. The statement should be:
select
p.*,
q.*,
cp.plan_handle
from
sys.dm_exec_cached_plans cp
cross apply sys.dm_exec_query_plan(cp.plan_handle) p
cross apply sys.dm_exec_sql_text(cp.plan_handle) as q
where
cp.cacheobjtype = 'Compiled Plan' and
p.query_plan.value('declare namespace
p="http://schemas.microsoft.com/sqlserver/2004/07/showplan";
max(//p:RelOp/@.Parallel)', 'float') > 0
Troubleshooting Performance Problems in SQL Server 2005
https://www.microsoft.com.nsatc.net...005/tsprfprb.ms
px
Is this article you want?
Sincerely,
Wei Lu
Microsoft Online Community Support
========================================
==========
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscript...ault.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscript...t/default.aspx.
========================================
==========
(This posting is provided "AS IS", with no warranties, and confers no
rights.)|||Hi ,
How is everything going? Please feel free to let me know if you need any
assistance.
Sincerely,
Wei Lu
Microsoft Online Community Support
========================================
==========
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
========================================
==========
This posting is provided "AS IS" with no warranties, and confers no rights.|||LOVELY, so many thanks
"Wei Lu [MSFT]" wrote:

> Hello Eliassal,
> I found that article. The statement should be:
> select
> p.*,
> q.*,
> cp.plan_handle
> from
> sys.dm_exec_cached_plans cp
> cross apply sys.dm_exec_query_plan(cp.plan_handle) p
> cross apply sys.dm_exec_sql_text(cp.plan_handle) as q
> where
> cp.cacheobjtype = 'Compiled Plan' and
> p.query_plan.value('declare namespace
> p="http://schemas.microsoft.com/sqlserver/2004/07/showplan";
> max(//p:RelOp/@.Parallel)', 'float') > 0
>
> Troubleshooting Performance Problems in SQL Server 2005
> l]
> ications.
> Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the community or a Microsoft Support
> Engineer within 1 business day is acceptable. Please note that each follow
> up response may take approximately 2 business days as the support
> professional working with you may need further investigation to reach the
> most efficient resolution. The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions or complex
> project analysis and dump analysis issues. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by contacting
> Microsoft Customer Support Services (CSS) at
> [url]http://msdn.microsoft.com/subscriptions/support/default.aspx." target="_blank">https://www.microsoft.com.nsatc.net...t/default.aspx.
> ========================================
==========
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
>|||Lines: 33
X-Tomcat-ID: 34576541
MIME-Version: 1.0
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Organization: Microsoft
X-Tomcat-NG: microsoft.public.sqlserver.xml
NNTP-Posting-Host: tomcatimport2.phx.gbl 10.201.218.182
Xref: leafnode.mcse.ms microsoft.public.sqlserver.xml:1829
Hello Eliassal,
My pleasure. If you have any question, please feel free to let me know.
Sincerely,
Wei Lu
Microsoft Online Community Support
========================================
==========
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscript...ault.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscript...t/default.aspx.
========================================
==========
(This posting is provided "AS IS", with no warranties, and confers no
rights.)sql

Query xml field in Query Plan DMV

I anot expertin XML and need to query a value in the field "query_plan" of
the "sys.dm_exec_query_plan" DMV. The value I is the whether queries has
Parallelism value more than 0. I remeber have seen something like
sys.dm_exec_query_plan.query_plan.value ('declare namespace.......
Is there in BOL a chapter on how querying special SQL xml schemas ?
Thanks in advance
Hello eliassal,
You could query the XML column in the DMV as any other XML column in SQL by
using the XQuery.
For example, I use this Statement to query the query_Plan:
select query_plan.query('declare namespace
showplan="http://schemas.microsoft.com/sqlserver/2004/07/showplan";
/showplan:ShowPlanXML/showplan:BatchSequence/showplan:Batch') from
sys.dm_exec_query_plan(<my plan handle id>)
For more detailed information about how to query the XML date using XQuery,
please refer this article:
XQuery Against the xml Data Type
http://msdn2.microsoft.com/en-us/library/ms189075.aspx
For more detailed information about the schema of the query_plan, pleaser
refer this article:
sys.dm_exec_query_plan
http://msdn2.microsoft.com/en-us/ms189747.aspx
http://schemas.microsoft.com/sqlserver/
Hope this will be helpful!
Sincerely,
Wei Lu
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
|||So many thanks, I tried so many times, so many syntaxes to work with the
"RelOp" element without success
In the sql schemq it is defined as follows :
<xsd:element name="RelOp" type="shp:RelOpType" />
<xsd:element name="ParameterList" type="shp:ColumnReferenceListType"
minOccurs="0" maxOccurs="1" />
As I said yesterday, I understood in a sql article that if the
max(...RelOp/@.parelle.....) > 0 gives us an idea if the query would be
paralleize.
I am deserate!!!HELP :-)
Thanks again
"Wei Lu [MSFT]" wrote:

> Hello eliassal,
> You could query the XML column in the DMV as any other XML column in SQL by
> using the XQuery.
> For example, I use this Statement to query the query_Plan:
> select query_plan.query('declare namespace
> showplan="http://schemas.microsoft.com/sqlserver/2004/07/showplan";
> /showplan:ShowPlanXML/showplan:BatchSequence/showplan:Batch') from
> sys.dm_exec_query_plan(<my plan handle id>)
> For more detailed information about how to query the XML date using XQuery,
> please refer this article:
> XQuery Against the xml Data Type
> http://msdn2.microsoft.com/en-us/library/ms189075.aspx
> For more detailed information about the schema of the query_plan, pleaser
> refer this article:
> sys.dm_exec_query_plan
> http://msdn2.microsoft.com/en-us/ms189747.aspx
> http://schemas.microsoft.com/sqlserver/
> Hope this will be helpful!
> Sincerely,
> Wei Lu
> Microsoft Online Community Support
> ==================================================
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
> ications.
> Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the community or a Microsoft Support
> Engineer within 1 business day is acceptable. Please note that each follow
> up response may take approximately 2 business days as the support
> professional working with you may need further investigation to reach the
> most efficient resolution. The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions or complex
> project analysis and dump analysis issues. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by contacting
> Microsoft Customer Support Services (CSS) at
> http://msdn.microsoft.com/subscriptions/support/default.aspx.
> ==================================================
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
>
>
|||Hello Eliassal,
I found that article. The statement should be:
select
p.*,
q.*,
cp.plan_handle
from
sys.dm_exec_cached_plans cp
cross apply sys.dm_exec_query_plan(cp.plan_handle) p
cross apply sys.dm_exec_sql_text(cp.plan_handle) as q
where
cp.cacheobjtype = 'Compiled Plan' and
p.query_plan.value('declare namespace
p="http://schemas.microsoft.com/sqlserver/2004/07/showplan";
max(//p:RelOp/@.Parallel)', 'float') > 0
Troubleshooting Performance Problems in SQL Server 2005
https://www.microsoft.com.nsatc.net/technet/prodtechnol/sql/2005/tsprfprb.ms
px
Is this article you want?
Sincerely,
Wei Lu
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
|||Hi ,
How is everything going? Please feel free to let me know if you need any
assistance.
Sincerely,
Wei Lu
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
|||LOVELY, so many thanks
"Wei Lu [MSFT]" wrote:

> Hello Eliassal,
> I found that article. The statement should be:
> select
> p.*,
> q.*,
> cp.plan_handle
> from
> sys.dm_exec_cached_plans cp
> cross apply sys.dm_exec_query_plan(cp.plan_handle) p
> cross apply sys.dm_exec_sql_text(cp.plan_handle) as q
> where
> cp.cacheobjtype = 'Compiled Plan' and
> p.query_plan.value('declare namespace
> p="http://schemas.microsoft.com/sqlserver/2004/07/showplan";
> max(//p:RelOp/@.Parallel)', 'float') > 0
>
> Troubleshooting Performance Problems in SQL Server 2005
> https://www.microsoft.com.nsatc.net/technet/prodtechnol/sql/2005/tsprfprb.ms
> px
> Is this article you want?
> Sincerely,
> Wei Lu
> Microsoft Online Community Support
> ==================================================
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
> ications.
> Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the community or a Microsoft Support
> Engineer within 1 business day is acceptable. Please note that each follow
> up response may take approximately 2 business days as the support
> professional working with you may need further investigation to reach the
> most efficient resolution. The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions or complex
> project analysis and dump analysis issues. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by contacting
> Microsoft Customer Support Services (CSS) at
> http://msdn.microsoft.com/subscriptions/support/default.aspx.
> ==================================================
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
>
|||Hello Eliassal,
My pleasure. If you have any question, please feel free to let me know.
Sincerely,
Wei Lu
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

query xml datatype

In SQL 2005, we've defined a column as type "xml". We'd like to query
that column so that its nodes are returned in traditional columnar
format. For instance, to get the first & last name nodes, we have code
like...
Select cast(Info.query('
declare namespace m="http://tempuri.org/MyInfo";
data(/m:info/m:firstname)') as varchar(200)) as FirstName,
cast(Info.query('
declare namespace m="http://tempuri.org/MyInfo";
data(/m:info/m:lastname)') as varchar(200)) as LastName
from MyTest
That seems like a lot of work to get the first & last name in columnar
format. Is there a better way to do this?
You can't write it a whole lot simpler.
Here's what I would write if firstname and lastname elements have open
content:
WITH XMLNAMESPACES('http://tempuri.org/MyInfo' AS m)
SELECT
Info.value('(/m:info/m:firstname/text())[1]','varchar(200)') AS
FirstName,
Info.value('(/m:info/m:lastname/text())[1]','varchar(200)') AS LastName
FROM MyTest
Note that value() method does both atomization (data()) of the resulting
XQuery sequence element (must be singleton) and mapping it to a SQL type
provided as the 2nd parameter.
If your XML column is typed and firstname and lastname elements have simple
type/content than you'd need to remove "/text()" from the above XQuery
expressions.
Note that if there could be multiple firstname/lastname elements per XML
instance and you needed each of them on a separate row you'd use nodes()
method in FROM clause.
Regards,
Eugene
This posting is provided "AS IS" with no warranties, and confers no rights.
"--Marty" <Martin.McDonald@.us.logicalis.com> wrote in message
news:1126718758.082803.55550@.g47g2000cwa.googlegro ups.com...
> In SQL 2005, we've defined a column as type "xml". We'd like to query
> that column so that its nodes are returned in traditional columnar
> format. For instance, to get the first & last name nodes, we have code
> like...
> Select cast(Info.query('
> declare namespace m="http://tempuri.org/MyInfo";
> data(/m:info/m:firstname)') as varchar(200)) as FirstName,
> cast(Info.query('
> declare namespace m="http://tempuri.org/MyInfo";
> data(/m:info/m:lastname)') as varchar(200)) as LastName
> from MyTest
> That seems like a lot of work to get the first & last name in columnar
> format. Is there a better way to do this?
>

query xml datatype

In SQL 2005, we've defined a column as type "xml". We'd like to query
that column so that its nodes are returned in traditional columnar
format. For instance, to get the first & last name nodes, we have code
like...
Select cast(Info.query('
declare namespace m="http://tempuri.org/MyInfo";
data(/m:info/m:firstname)') as varchar(200)) as FirstName,
cast(Info.query('
declare namespace m="http://tempuri.org/MyInfo";
data(/m:info/m:lastname)') as varchar(200)) as LastName
from MyTest
That seems like a lot of work to get the first & last name in columnar
format. Is there a better way to do this?You can't write it a whole lot simpler.
Here's what I would write if firstname and lastname elements have open
content:
WITH XMLNAMESPACES('http://tempuri.org/MyInfo' AS m)
SELECT
Info.value('(/m:info/m:firstname/text())[1]','varchar(200)') AS
FirstName,
Info.value('(/m:info/m:lastname/text())[1]','varchar(200)') AS LastName
FROM MyTest
Note that value() method does both atomization (data()) of the resulting
XQuery sequence element (must be singleton) and mapping it to a SQL type
provided as the 2nd parameter.
If your XML column is typed and firstname and lastname elements have simple
type/content than you'd need to remove "/text()" from the above XQuery
expressions.
Note that if there could be multiple firstname/lastname elements per XML
instance and you needed each of them on a separate row you'd use nodes()
method in FROM clause.
Regards,
Eugene
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"--Marty" <Martin.McDonald@.us.logicalis.com> wrote in message
news:1126718758.082803.55550@.g47g2000cwa.googlegroups.com...
> In SQL 2005, we've defined a column as type "xml". We'd like to query
> that column so that its nodes are returned in traditional columnar
> format. For instance, to get the first & last name nodes, we have code
> like...
> Select cast(Info.query('
> declare namespace m="http://tempuri.org/MyInfo";
> data(/m:info/m:firstname)') as varchar(200)) as FirstName,
> cast(Info.query('
> declare namespace m="http://tempuri.org/MyInfo";
> data(/m:info/m:lastname)') as varchar(200)) as LastName
> from MyTest
> That seems like a lot of work to get the first & last name in columnar
> format. Is there a better way to do this?
>

Query XML datasource

I have an XML file that I receive from a vendor and would like to report
from this data every morning. Can anyone send me a link where I can do
this? I do not have a schema at this time but I think I can create one if
needed.
Thanks
Scottsee the thread
http://groups.google.com/group/microsoft.public.sqlserver.reportingsvcs/browse_thread/thread/d8d798424508e0e8/c4ceb1e126528133?lnk=raot#c4ceb1e126528133
I think your solution will also depend on
[1] how do you receive the XML file from the vendor?
[2] how do you like the report every morning? (schedule,
auto-delivery?)
Scott M wrote:
> I have an XML file that I receive from a vendor and would like to report
> from this data every morning. Can anyone send me a link where I can do
> this? I do not have a schema at this time but I think I can create one if
> needed.
> Thanks
> Scott|||Will this also work in RS 2000?
<siva.jasthi@.gmail.com> wrote in message
news:1134501012.316584.125040@.g44g2000cwa.googlegroups.com...
> see the thread
> http://groups.google.com/group/microsoft.public.sqlserver.reportingsvcs/browse_thread/thread/d8d798424508e0e8/c4ceb1e126528133?lnk=raot#c4ceb1e126528133
>
> I think your solution will also depend on
> [1] how do you receive the XML file from the vendor?
> [2] how do you like the report every morning? (schedule,
> auto-delivery?)
>
>
> Scott M wrote:
>> I have an XML file that I receive from a vendor and would like to report
>> from this data every morning. Can anyone send me a link where I can do
>> this? I do not have a schema at this time but I think I can create one
>> if
>> needed.
>> Thanks
>> Scott
>|||Hi Scott,
Unfortunately, it will not work in SQL Server 2000 Reporting Services.
Sincerely yours,
Michael Cheng
Microsoft Online Partner Support
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=====================================================This posting is provided "AS IS" with no warranties, and confers no rights.|||Is there an online tutorial for how to create a data extension for that?
"Michael Cheng [MSFT]" <v-mingqc@.online.microsoft.com> wrote in message
news:YUstdbIAGHA.832@.TK2MSFTNGXA02.phx.gbl...
> Hi Scott,
> Unfortunately, it will not work in SQL Server 2000 Reporting Services.
>
> Sincerely yours,
> Michael Cheng
> Microsoft Online Partner Support
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> =====================================================> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>|||Hi Scott,
Thanks for the respond.
I believe the following articles might help
Build an XML Data Extension for SQL Server Reporting Services
http://www.devx.com/dbzone/Article/21214
Tutorial: Using XML Data in a Report
http://msdn2.microsoft.com/en-us/library/ms345334(en-US,SQL.90).aspx
Hope this helps.
Sincerely yours,
Michael Cheng
Microsoft Online Partner Support
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=====================================================This posting is provided "AS IS" with no warranties, and confers no rights.|||I am not understanding from the MSDN article in this post where do you put
the XML file to connect to for your database.
"Michael Cheng [MSFT]" wrote:
> Hi Scott,
> Thanks for the respond.
> I believe the following articles might help
> Build an XML Data Extension for SQL Server Reporting Services
> http://www.devx.com/dbzone/Article/21214
> Tutorial: Using XML Data in a Report
> http://msdn2.microsoft.com/en-us/library/ms345334(en-US,SQL.90).aspx
> Hope this helps.
>
> Sincerely yours,
> Michael Cheng
> Microsoft Online Partner Support
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> =====================================================> This posting is provided "AS IS" with no warranties, and confers no rights.
>|||That first article looks like it might be what I need. I'll let you guys
know.
Thanks VERY much!!
Scott
"Michael Cheng [MSFT]" <v-mingqc@.online.microsoft.com> wrote in message
news:ktNF%23pVAGHA.1236@.TK2MSFTNGXA02.phx.gbl...
> Hi Scott,
> Thanks for the respond.
> I believe the following articles might help
> Build an XML Data Extension for SQL Server Reporting Services
> http://www.devx.com/dbzone/Article/21214
> Tutorial: Using XML Data in a Report
> http://msdn2.microsoft.com/en-us/library/ms345334(en-US,SQL.90).aspx
> Hope this helps.
>
> Sincerely yours,
> Michael Cheng
> Microsoft Online Partner Support
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> =====================================================> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>|||Hi Scott,
You are welcome :) If you have any questions or concerns next time, don't
hesitate to let me know. We are always here to be of assistance!
Sincerely yours,
Michael Cheng
Microsoft Online Partner Support
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=====================================================This posting is provided "AS IS" with no warranties, and confers no rights.

Wednesday, March 21, 2012

query to xml question

I have a table that contains 3 columns SiteID, Results and date. the table has 4 rows. I want to query the table and end up with 1 row that combines all the field into in the Results Column.

so in table form it looks like

627 test 3/3/7
627 bob 3/3/7
627 tom 3/9/7
627 rob 3/8/7

I want the resulting query to bring back one row:

test,bob,tom,rob

the following query will do 90% of what I want,

SELECT test +','
FROM #temp1
FORXMLPATH('')

BUT I cannot figure out how to provide a column name for the query result. instead I appear to get a guid of XML_F52E2B61-18A1-11d1-B105-00805F49916B

Q - is there a way to name the column, or is there a different way to create this query result without using XML?

I am us

Jim:

The best way is to make your select statement into a "derived table" or a correlated subquery; For example:

create table #temp1
( SiteID integer,
Results varchar(10),
date datetime
)
insert into #temp1 values (627, 'billy joe', '3/3/7')
insert into #temp1 values (627, 'bob', '3/3/7')
insert into #temp1 values (627, 'tom', '3/9/7')
insert into #temp1 values (627, 'rob', '3/8/7')

select distinct
siteId,
replace(replace(
( select replace (x.results, ' ', '~') as [data()]
from #temp1 x
where x.siteId = x.siteId
order by date
for xml path ('')
), ' ', ','), '~', ' ') as dataLabel
from #temp1 a

-- siteId dataLabel
-- --
-- 627 billy joe,bob,rob,tom

go

drop table #temp1
go

|||

selectcast((SELECT test +','FROM #temp1 FORXMLPATH(''))asvarchar(max))as YourName

|||I think I like Konstantin's better.|||

Thanks to both of you for the quick reply, they both work, but think I will use Konstantin's

|||

Actually I now have a different problem:

I am using

select siteid, Cast((SELECT Anomalies+ ',' FROM #temp1 FOR XML PATH('')) as varchar(max) ) as Anomaly from #temp1

this does work, sort of.... But it creates the result for all records in the table. I need it to create a seperate record for each siteid, otherwise all the resulting data is the same for all siteids?

any ideas?

|||Just add filter to subquery:
select siteid, Cast((SELECT Anomalies+ ',' FROM #temp1 where siteid=t.siteid FOR XML PATH('')) as varchar(max) ) as Anomaly from #temp1 t
sql

Query to return Xml column data as relational table - how?

Greetings,

I've just begun storing Xml in a SQL Server Xml column. I've got a column that contains something like this 3 element example:

<document xmlns="http://www.lotus.com/dxl" version="7.0" maintenanceversion="2.0" replicaid="852571B800111CE3" form="data">

<item name="OriginalModTime">

<datetime dst="true">20060813T135156,51-05</datetime>

</item>

<item name="Genius_Status_1">

<text>1</text>

</item>

<item name="archive_date">

<datetime>20040331</datetime>

</item>

</document>

I need to write a query that will return a combination of attribute and data values at different "levels". This is what I must achieve as query results:

Name Type Value

- - --

OriginalModTime datetime 20060813T135156,51-05

Genius_Status_1 text 1

archive_date datetime 20040331

Each resultset row must correspond to one "item" element.

Can someone give me an idea of what this query should look like? I'm trying to puzzle my way through xquery...

Thanks,

BCB

I've got everything but the "Type" column figured out. This query returns "Name" and "Value". Can someone suggest the missing logic to return the "Type" value?

Thanks... BCB

SELECT TOP 1000

Item.value('./@.name', 'NVARCHAR(MAX)') as [Notes Field],

Item.value('.', 'NVARCHAR(MAX)') as Value

FROM

NotesAudit

CROSS APPLY

XmlBlob.nodes('declare namespace MI="http://www.lotus.com/dxl"; /MIBig Smileocument/MI:item') AS T1(Item)

|||

This is the working query:

SELECT TOP 1000

Item.value('./@.name', 'NVARCHAR(MAX)') AS [Notes Field Name],

Item.value('local-name(./*[1])', 'NVARCHAR(256)') AS [Data Type],

Item.value('.', 'NVARCHAR(MAX)') AS [Field Value]

FROM

NotesAudit

CROSS APPLY

XmlBlob.nodes('declare namespace MI="http://www.lotus.com/dxl"; /MIBig Smileocument/MI:item') AS T1(Item)

sql

Query to return Xml column data as relational table - how?

Greetings,

I've just begun storing Xml in a SQL Server Xml column. I've got a column that contains something like this 3 element example:

<document xmlns="http://www.lotus.com/dxl" version="7.0" maintenanceversion="2.0" replicaid="852571B800111CE3" form="data">

<item name="OriginalModTime">

<datetime dst="true">20060813T135156,51-05</datetime>

</item>

<item name="Genius_Status_1">

<text>1</text>

</item>

<item name="archive_date">

<datetime>20040331</datetime>

</item>

</document>

I need to write a query that will return a combination of attribute and data values at different "levels". This is what I must achieve as query results:

Name Type Value

- - --

OriginalModTime datetime 20060813T135156,51-05

Genius_Status_1 text 1

archive_date datetime 20040331

Each resultset row must correspond to one "item" element.

Can someone give me an idea of what this query should look like? I'm trying to puzzle my way through xquery...

Thanks,

BCB

I've got everything but the "Type" column figured out. This query returns "Name" and "Value". Can someone suggest the missing logic to return the "Type" value?

Thanks... BCB

SELECT TOP 1000

Item.value('./@.name', 'NVARCHAR(MAX)') as [Notes Field],

Item.value('.', 'NVARCHAR(MAX)') as Value

FROM

NotesAudit

CROSS APPLY

XmlBlob.nodes('declare namespace MI="http://www.lotus.com/dxl"; /MIBig Smileocument/MI:item') AS T1(Item)

|||

This is the working query:

SELECT TOP 1000

Item.value('./@.name', 'NVARCHAR(MAX)') AS [Notes Field Name],

Item.value('local-name(./*[1])', 'NVARCHAR(256)') AS [Data Type],

Item.value('.', 'NVARCHAR(MAX)') AS [Field Value]

FROM

NotesAudit

CROSS APPLY

XmlBlob.nodes('declare namespace MI="http://www.lotus.com/dxl"; /MIBig Smileocument/MI:item') AS T1(Item)

Monday, March 12, 2012

Query to get XML in output (SQL Server 2000)

Hi all,
Can anyone help me with a SQL query to get the following XMLs in result.
This is for SQL Server 2000
First XML
<TagA id="NR_2">
<TagB id="2">Factory</TagB>
<TagC>WASHINGTON</TagC>
<TagD>999999999</TagD>
<TagE id="123456">Other</TagE>
<TagF>
<TagG>COMPANY</TagG>
<TagH>0123</TagH>
</TagF>
</TagA>
Second XML
<TagA id="NR_3">
<TagB id="2">Factory</TagB>
<TagC>GEORGIA</TagC>
<TagD>GA</TagD>
<TagE id="123456">Other</TagE>
<TagF/>
</TagA>
Look at the FOR XML EXPLICIT functionality.
If you could provide us with some example table, we could probably help you
with the query.
Best regards
Michael
"Umar" <Umar@.discussions.microsoft.com> wrote in message
news:1F4BC4B9-186A-46D8-BFB0-BA0BD657B184@.microsoft.com...
> Hi all,
> Can anyone help me with a SQL query to get the following XMLs in result.
> This is for SQL Server 2000
> First XML
> <TagA id="NR_2">
> <TagB id="2">Factory</TagB>
> <TagC>WASHINGTON</TagC>
> <TagD>999999999</TagD>
> <TagE id="123456">Other</TagE>
> <TagF>
> <TagG>COMPANY</TagG>
> <TagH>0123</TagH>
> </TagF>
> </TagA>
>
>
> Second XML
> <TagA id="NR_3">
> <TagB id="2">Factory</TagB>
> <TagC>GEORGIA</TagC>
> <TagD>GA</TagD>
> <TagE id="123456">Other</TagE>
> <TagF/>
> </TagA>
>

Query to get XML in output (SQL Server 2000)

Hi all,
Can anyone help me with a query to get the following XMLs in result
First XML
<TagA id="NR_2">
<TagB id="2">Factory</TagB>
<TagC>WASHINGTON</TagC>
<TagD>999999999</TagD>
<TagE id="123456">Other</TagE>
<TagF>
<TagG>COMPANY</TagG>
<TagH>0123</TagH>
</TagF>
</TagA>
Second XML
<TagA id="NR_3">
<TagB id="2">Factory</TagB>
<TagC>GEORGIA</TagC>
<TagD>GA</TagD>
<TagE id="123456">Other</TagE>
<TagF/>
</TagA>
Umar,
If you haven't already, you may want to see:
Using EXPLICIT Mode
http://msdn.microsoft.com/library/de...enxml_4y91.asp
HTH
Jerry
"Umar" <Umar@.discussions.microsoft.com> wrote in message
news:23A25C27-983E-46B0-A12F-1C7EF28812D0@.microsoft.com...
> Hi all,
> Can anyone help me with a query to get the following XMLs in result
> First XML
> <TagA id="NR_2">
> <TagB id="2">Factory</TagB>
> <TagC>WASHINGTON</TagC>
> <TagD>999999999</TagD>
> <TagE id="123456">Other</TagE>
> <TagF>
> <TagG>COMPANY</TagG>
> <TagH>0123</TagH>
> </TagF>
> </TagA>
>
>
> Second XML
> <TagA id="NR_3">
> <TagB id="2">Factory</TagB>
> <TagC>GEORGIA</TagC>
> <TagD>GA</TagD>
> <TagE id="123456">Other</TagE>
> <TagF/>
> </TagA>
>
|||Hi Jerry,
I have seen this.
If you note, the tags have attributes and values. Is there a way I can do it
one sql. I know this can be done if child tags have values only. e.g,
<TagA id="NR_2">
<TagC>WASHINGTON</TagC>
</TagA>
But note that my desired result requires attributes in child tags too. I
know this can be done by using UNION ALL, but is there a way I do it one
query?
"Jerry Spivey" wrote:

> Umar,
> If you haven't already, you may want to see:
> Using EXPLICIT Mode
> http://msdn.microsoft.com/library/de...enxml_4y91.asp
> HTH
> Jerry
> "Umar" <Umar@.discussions.microsoft.com> wrote in message
> news:23A25C27-983E-46B0-A12F-1C7EF28812D0@.microsoft.com...
>
>
|||You can make something an attribute or an element if you use XML EXPLICIT. I
would try to stay away from keywords like "id"m but for reference I included
you sample code below. Use the attribute name to make it an attribute, use
the keywork "element" to make it an element.
SELECT 1 as Tag,
NULL as Parent,
taga.id as [TagA!1!id],
NULL as [TagB!2!id],
NULL as [TagB!2!element]
FROM taga
UNION ALL
SELECT 2,
1,
taga.id,
tagb.id,
tagb.name
FROM taga INNER JOIN tagb ON taga.id = tagb.refid
ORDER BY [TagA!1!id], [TagB!2!id]
FOR XML EXPLICIT
HTH,
John Scragg
"Umar" wrote:
[vbcol=seagreen]
> Hi Jerry,
> I have seen this.
> If you note, the tags have attributes and values. Is there a way I can do it
> one sql. I know this can be done if child tags have values only. e.g,
> <TagA id="NR_2">
> <TagC>WASHINGTON</TagC>
> </TagA>
> But note that my desired result requires attributes in child tags too. I
> know this can be done by using UNION ALL, but is there a way I do it one
> query?
> "Jerry Spivey" wrote:

Query to get XML in output (SQL Server 2000)

Hi all,
Can anyone help me with a SQL query to get the following XMLs in result.
This is for SQL Server 2000
First XML
<TagA id="NR_2">
<TagB id="2">Factory</TagB>
<TagC>WASHINGTON</TagC>
<TagD>999999999</TagD>
<TagE id="123456">Other</TagE>
<TagF>
<TagG>COMPANY</TagG>
<TagH>0123</TagH>
</TagF>
</TagA>
Second XML
<TagA id="NR_3">
<TagB id="2">Factory</TagB>
<TagC>GEORGIA</TagC>
<TagD>GA</TagD>
<TagE id="123456">Other</TagE>
<TagF/>
</TagA>Look at the FOR XML EXPLICIT functionality.
If you could provide us with some example table, we could probably help you
with the query.
Best regards
Michael
"Umar" <Umar@.discussions.microsoft.com> wrote in message
news:1F4BC4B9-186A-46D8-BFB0-BA0BD657B184@.microsoft.com...
> Hi all,
> Can anyone help me with a SQL query to get the following XMLs in result.
> This is for SQL Server 2000
> First XML
> <TagA id="NR_2">
> <TagB id="2">Factory</TagB>
> <TagC>WASHINGTON</TagC>
> <TagD>999999999</TagD>
> <TagE id="123456">Other</TagE>
> <TagF>
> <TagG>COMPANY</TagG>
> <TagH>0123</TagH>
> </TagF>
> </TagA>
>
>
> Second XML
> <TagA id="NR_3">
> <TagB id="2">Factory</TagB>
> <TagC>GEORGIA</TagC>
> <TagD>GA</TagD>
> <TagE id="123456">Other</TagE>
> <TagF/>
> </TagA>
>

Query to get XML in output (SQL Server 2000)

Hi all,
Can anyone help me with a query to get the following XMLs in result
First XML
<TagA id="NR_2">
<TagB id="2">Factory</TagB>
<TagC>WASHINGTON</TagC>
<TagD>999999999</TagD>
<TagE id="123456">Other</TagE>
<TagF>
<TagG>COMPANY</TagG>
<TagH>0123</TagH>
</TagF>
</TagA>
Second XML
<TagA id="NR_3">
<TagB id="2">Factory</TagB>
<TagC>GEORGIA</TagC>
<TagD>GA</TagD>
<TagE id="123456">Other</TagE>
<TagF/>
</TagA>Umar,
If you haven't already, you may want to see:
Using EXPLICIT Mode
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsql/ac_openxml_4y91.asp
HTH
Jerry
"Umar" <Umar@.discussions.microsoft.com> wrote in message
news:23A25C27-983E-46B0-A12F-1C7EF28812D0@.microsoft.com...
> Hi all,
> Can anyone help me with a query to get the following XMLs in result
> First XML
> <TagA id="NR_2">
> <TagB id="2">Factory</TagB>
> <TagC>WASHINGTON</TagC>
> <TagD>999999999</TagD>
> <TagE id="123456">Other</TagE>
> <TagF>
> <TagG>COMPANY</TagG>
> <TagH>0123</TagH>
> </TagF>
> </TagA>
>
>
> Second XML
> <TagA id="NR_3">
> <TagB id="2">Factory</TagB>
> <TagC>GEORGIA</TagC>
> <TagD>GA</TagD>
> <TagE id="123456">Other</TagE>
> <TagF/>
> </TagA>
>|||Hi Jerry,
I have seen this.
If you note, the tags have attributes and values. Is there a way I can do it
one sql. I know this can be done if child tags have values only. e.g,
<TagA id="NR_2">
<TagC>WASHINGTON</TagC>
</TagA>
But note that my desired result requires attributes in child tags too. I
know this can be done by using UNION ALL, but is there a way I do it one
query?
"Jerry Spivey" wrote:
> Umar,
> If you haven't already, you may want to see:
> Using EXPLICIT Mode
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsql/ac_openxml_4y91.asp
> HTH
> Jerry
> "Umar" <Umar@.discussions.microsoft.com> wrote in message
> news:23A25C27-983E-46B0-A12F-1C7EF28812D0@.microsoft.com...
> > Hi all,
> >
> > Can anyone help me with a query to get the following XMLs in result
> >
> > First XML
> >
> > <TagA id="NR_2">
> > <TagB id="2">Factory</TagB>
> > <TagC>WASHINGTON</TagC>
> > <TagD>999999999</TagD>
> > <TagE id="123456">Other</TagE>
> > <TagF>
> > <TagG>COMPANY</TagG>
> > <TagH>0123</TagH>
> > </TagF>
> > </TagA>
> >
> >
> >
> >
> > Second XML
> >
> > <TagA id="NR_3">
> > <TagB id="2">Factory</TagB>
> > <TagC>GEORGIA</TagC>
> > <TagD>GA</TagD>
> > <TagE id="123456">Other</TagE>
> > <TagF/>
> > </TagA>
> >
>
>|||You can make something an attribute or an element if you use XML EXPLICIT. I
would try to stay away from keywords like "id"m but for reference I included
you sample code below. Use the attribute name to make it an attribute, use
the keywork "element" to make it an element.
SELECT 1 as Tag,
NULL as Parent,
taga.id as [TagA!1!id],
NULL as [TagB!2!id],
NULL as [TagB!2!element]
FROM taga
UNION ALL
SELECT 2,
1,
taga.id,
tagb.id,
tagb.name
FROM taga INNER JOIN tagb ON taga.id = tagb.refid
ORDER BY [TagA!1!id], [TagB!2!id]
FOR XML EXPLICIT
HTH,
John Scragg
"Umar" wrote:
> Hi Jerry,
> I have seen this.
> If you note, the tags have attributes and values. Is there a way I can do it
> one sql. I know this can be done if child tags have values only. e.g,
> <TagA id="NR_2">
> <TagC>WASHINGTON</TagC>
> </TagA>
> But note that my desired result requires attributes in child tags too. I
> know this can be done by using UNION ALL, but is there a way I do it one
> query?
> "Jerry Spivey" wrote:
> > Umar,
> >
> > If you haven't already, you may want to see:
> >
> > Using EXPLICIT Mode
> > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsql/ac_openxml_4y91.asp
> >
> > HTH
> >
> > Jerry
> > "Umar" <Umar@.discussions.microsoft.com> wrote in message
> > news:23A25C27-983E-46B0-A12F-1C7EF28812D0@.microsoft.com...
> > > Hi all,
> > >
> > > Can anyone help me with a query to get the following XMLs in result
> > >
> > > First XML
> > >
> > > <TagA id="NR_2">
> > > <TagB id="2">Factory</TagB>
> > > <TagC>WASHINGTON</TagC>
> > > <TagD>999999999</TagD>
> > > <TagE id="123456">Other</TagE>
> > > <TagF>
> > > <TagG>COMPANY</TagG>
> > > <TagH>0123</TagH>
> > > </TagF>
> > > </TagA>
> > >
> > >
> > >
> > >
> > > Second XML
> > >
> > > <TagA id="NR_3">
> > > <TagB id="2">Factory</TagB>
> > > <TagC>GEORGIA</TagC>
> > > <TagD>GA</TagD>
> > > <TagE id="123456">Other</TagE>
> > > <TagF/>
> > > </TagA>
> > >
> >
> >
> >

Query to get XML in output (SQL Server 2000)

Hi all,
Can anyone help me with a query to get the following XMLs in result
First XML
<TagA id="NR_2">
<TagB id="2">Factory</TagB>
<TagC>WASHINGTON</TagC>
<TagD>999999999</TagD>
<TagE id="123456">Other</TagE>
<TagF>
<TagG>COMPANY</TagG>
<TagH>0123</TagH>
</TagF>
</TagA>
Second XML
<TagA id="NR_3">
<TagB id="2">Factory</TagB>
<TagC>GEORGIA</TagC>
<TagD>GA</TagD>
<TagE id="123456">Other</TagE>
<TagF/>
</TagA>Umar,
If you haven't already, you may want to see:
Using EXPLICIT Mode
http://msdn.microsoft.com/library/d...r />
_4y91.asp
HTH
Jerry
"Umar" <Umar@.discussions.microsoft.com> wrote in message
news:23A25C27-983E-46B0-A12F-1C7EF28812D0@.microsoft.com...
> Hi all,
> Can anyone help me with a query to get the following XMLs in result
> First XML
> <TagA id="NR_2">
> <TagB id="2">Factory</TagB>
> <TagC>WASHINGTON</TagC>
> <TagD>999999999</TagD>
> <TagE id="123456">Other</TagE>
> <TagF>
> <TagG>COMPANY</TagG>
> <TagH>0123</TagH>
> </TagF>
> </TagA>
>
>
> Second XML
> <TagA id="NR_3">
> <TagB id="2">Factory</TagB>
> <TagC>GEORGIA</TagC>
> <TagD>GA</TagD>
> <TagE id="123456">Other</TagE>
> <TagF/>
> </TagA>
>|||Hi Jerry,
I have seen this.
If you note, the tags have attributes and values. Is there a way I can do it
one sql. I know this can be done if child tags have values only. e.g,
<TagA id="NR_2">
<TagC>WASHINGTON</TagC>
</TagA>
But note that my desired result requires attributes in child tags too. I
know this can be done by using UNION ALL, but is there a way I do it one
query?
"Jerry Spivey" wrote:

> Umar,
> If you haven't already, you may want to see:
> Using EXPLICIT Mode
> http://msdn.microsoft.com/library/d.../>
ml_4y91.asp
> HTH
> Jerry
> "Umar" <Umar@.discussions.microsoft.com> wrote in message
> news:23A25C27-983E-46B0-A12F-1C7EF28812D0@.microsoft.com...
>
>|||You can make something an attribute or an element if you use XML EXPLICIT.
I
would try to stay away from keywords like "id"m but for reference I included
you sample code below. Use the attribute name to make it an attribute, use
the keywork "element" to make it an element.
SELECT 1 as Tag,
NULL as Parent,
taga.id as [TagA!1!id],
NULL as [TagB!2!id],
NULL as [TagB!2!element]
FROM taga
UNION ALL
SELECT 2,
1,
taga.id,
tagb.id,
tagb.name
FROM taga INNER JOIN tagb ON taga.id = tagb.refid
ORDER BY [TagA!1!id], [TagB!2!id]
FOR XML EXPLICIT
HTH,
John Scragg
"Umar" wrote:
[vbcol=seagreen]
> Hi Jerry,
> I have seen this.
> If you note, the tags have attributes and values. Is there a way I can do
it
> one sql. I know this can be done if child tags have values only. e.g,
> <TagA id="NR_2">
> <TagC>WASHINGTON</TagC>
> </TagA>
> But note that my desired result requires attributes in child tags too. I
> know this can be done by using UNION ALL, but is there a way I do it one
> query?
> "Jerry Spivey" wrote:
>

Wednesday, March 7, 2012

Query timeouts

I've created a report in RS 2006 that uses an XML data source. The source
uses a web service that takes sufficiently long to return that my query times
out.
can anyone tell me how can I increase the timeout value of the query?Click on the ... of the dataset. The timeout is on that page.
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"ekkis" <ekkis@.discussions.microsoft.com> wrote in message
news:CC99FCCF-D3B5-4AB6-AD31-BE35A002748E@.microsoft.com...
> I've created a report in RS 2006 that uses an XML data source. The source
> uses a web service that takes sufficiently long to return that my query
> times
> out.
> can anyone tell me how can I increase the timeout value of the query?
>