Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

SQL 2005 HAS BETTER OPTIONS FOR PRODUCING THE RESULTS

 
   Database Help (Home) -> XML RSS
Next:  fatal exception c0000005 EXCEPTION_ACCESS_VIOLATI..  
Author Message
Doug Lubey

External


Since: Nov 13, 2008
Posts: 1



(Msg. 1) Posted: Thu Nov 13, 2008 1:10 pm
Post subject: SQL 2005 HAS BETTER OPTIONS FOR PRODUCING THE RESULTS
Archived from groups: microsoft>public>sqlserver>xml (more info?)

THE "QUERY FROM HELL" IS ROUGH AROUND THE EDGES. i HAVE WRITTEN 5 OF THESE, WHICH RUN IN A PRODUCTION ENVIRONMENT.

BUT WE ARE CONVERTING ALL OF THEM TO THE XML PATH
STATEMENT IN SQL 2005.

here is the error I got
sql 2005 Msg 1086 for xml path using derived table syntax

Msg 1086, Level 15, State 1, Line 72
The FOR XML clause is invalid in views, inline functions, derived
tables, and subqueries when they contain a set operator. To work
around, wrap the SELECT containing a set operator using derived table
syntax and apply FOR XML on top of it.


and here is the work around I found:
--------------------------------------------------------
-- #1 WORKS JUST FINE
--------------------------------------------------------
-- select 'dude' as 'GovernmentId'
-- union select 'dude2' as 'GovernmentId'
-- for XML PATH('')
--
-- produces:
-- <GovernmentId>dude</GovernmentId>
-- <GovernmentId>dude2</GovernmentId>
--
----------- EXAMPLE #2>
--
-- select
-- '1' as 'GovernmentId/@id',
-- 'dude' as 'GovernmentId'
-- union select
-- '2' as 'GovernmentId/@id',
-- 'dude2' as 'GovernmentId'
-- for XML PATH('')
--
-- produces:
-- <GovernmentId id="1">dude</GovernmentId>
-- <GovernmentId id="2">dude2</GovernmentId>
--
----------- EXAMPLE #3>
--
-- select '' as 'PersonName',
-- (select
-- PersonId as 'Identity/@Id',
-- PersonName as 'Identity'
-- from
-- (select
-- '1' as PersonId,
-- 'dude' as PersonName
-- union select
-- '2' as PersonId,
-- 'dude2' as PersonName
-- ) as t1
-- for xml Path(''), Type
-- ) as 'Person'
-- for xml PATH('Person')
--
-- PRODUCES:
-- <Person>
-- <PersonName></PersonName>
-- <Person>
-- <Identity Id="1">dude</Identity>
-- <Identity Id="2">dude2</Identity>
-- </Person>
-- </Person>
--
----------- EXAMPLE #4>
--
-- select '' as 'Person/PersonName',
-- (select
-- PersonId as 'Identity/@Id',
-- PersonName as 'Identity'
-- from
-- (select
-- '1' as PersonId,
-- 'dude' as PersonName
-- union select
-- '2' as PersonId,
-- 'dude2' as PersonName
-- ) as t1
-- for xml Path(''), Type
-- ) as 'Person'
-- for xml PATH('')
-- PRODUCES:
--<Person>
-- <PersonName></PersonName>
-- <Identity Id="1">dude</Identity>
-- <Identity Id="2">dude2</Identity>
--</Person>
--------------------------------------------------------


Although, Thanks for the tips using sqlxml:

Also here is a good reference (just was not enough for me)..

http://technet.microsoft.com/en-us/library/ms345137(SQL.90).aspx

Thanks,

Doug Lubey of Louisiana
www.DougLubey.com

 >> Stay informed about: SQL 2005 HAS BETTER OPTIONS FOR PRODUCING THE RESULTS 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
SQLXML3 Multiple FORXML Results - It doesn't appear that either SQLXML3 or standard SQLCommand.ExecuteXmlReader supports a stored procedure that returns multiple XML results; Example; CREATE Procedure .... SELECT ... FORXML AUTO SELECT ... FORXML AUTO Are there any known workarounds?....

import xml to sql 2005 - Is there a tool to import xml to sql? Is there something else that can be used beside the Bulk Load Component. I would think MS had something. xml file is from store front. Thank you Dee

how to insert xml into sql 2005 - Using the following code how do I actually insert the data from the xml file into the sql 2005 database: declare @xml varchar(max) declare @xmlHandle int -- Bulk load the xml from the file set @xml = ( select * from openrowset (..

Create 2005 local cubes - I need to create a windows application in which I can programmatically create local cubes from SQL Server 2005 databases using C#. I was able to do this in SQL Server 2000, but I cannot get the same results after upgrading to 2005 because the CREATE..

How do you read an XML schema in SQL 2005 - I have some data that came to me in XSD. How can this be read into an SQL 2005 database? I also have a few XML Schemas and need to know how this can be ready into an SQL 2005 database? Thanks for any help Dee
   Database Help (Home) -> XML All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]