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

Wednesday, March 28, 2012

how to insert into a table using a select from xml

Good Day,

I am passing some XML into a stored procedure:

<answers>
<answer id="60" text="" />
<answer id="65" text="A moderate form of learning disability" />
<answer id="68" text="We will keep ASD checked" />
<answer id="70" text="" />
</answers>

Along with a memberid and questionid.

I was wondering how I can get this into a table

CREATE TABLE [dbo].[Answers]([PrimaryKeyID] [int]NOT NULL,[MemberID] [int]NOT NULL,[QuestionID] [int]NOT NULL,[AnswerID] [int]NOT NULL,[FreText] [varchar](255) COLLATE Latin1_General_CI_ASNULL)ON [PRIMARY]
What I would also like to do is if the text attribute is empty then put a NULL in the FreText field.
I think I am looking for
 
Insert into MyTable (Select @.MemID, @.QuesID,'somexpathforanswer','somexpathfortext'-- if empty then NULLFrom @.MyXML )
Any ideas - places to to look - thoughts Aprreciated
Kal

you can try to use OPENXML see example from T_SQL help below

DECLARE @.idoc intDECLARE @.doc varchar(1000)SET @.doc ='<ROOT><Customer CustomerID="VINET" ContactName="Paul Henriot"> <Order CustomerID="VINET" EmployeeID="5" OrderDate="1996-07-04T00:00:00"> <OrderDetail OrderID="10248" ProductID="11" Quantity="12"/> <OrderDetail OrderID="10248" ProductID="42" Quantity="10"/> </Order></Customer><Customer CustomerID="LILAS" ContactName="Carlos Gonzlez"> <Order CustomerID="LILAS" EmployeeID="3" OrderDate="1996-08-16T00:00:00"> <OrderDetail OrderID="10283" ProductID="72" Quantity="3"/> </Order></Customer></ROOT>'--Create an internal representation of the XML document.EXEC sp_xml_preparedocument @.idoc OUTPUT, @.doc-- Execute a SELECT statement that uses the OPENXML rowset provider.SELECT *FROM OPENXML (@.idoc, '/ROOT/Customer',1) WITH (CustomerID varchar(10), ContactName varchar(20))

How to insert data with dollar ($) first with sqlxml ?

Hi,
I wish to insert the following data into an sql table using sqlxml. All
columns in the table are varchar. The crafted xml is as follow:
<ROOT xmlns:updg="urn:schemas-microsoft-com:xml-updategram">
<updg:sync><updg:after>
<temp_Outstanding drawdownApp="LOA"
drawdownId="XYZ"
facilityId="$J5EZEFN">
</temp_Outstanding>
</updg:after></updg:sync>
</ROOT>
But this lamely fail with the following error: Invalid XML elements found
inside sync block (HRESULT="0x80004005").
The code to perform the update is as follow:
SqlXmlCommand cmd = new SqlXmlCommand(conn);
cmd.CommandType = SqlXmlCommandType.UpdateGram;
cmd.CommandText = content;
stm = cmd.ExecuteStream();
The trouble seems to come from the $J5EZEFN field. Is there a way to insert
something into a table that begin with a dollar ($) sign ?
It seems that $XXX is used to pass parameters - but, well, I do not want to
pass parameter. I just want to insert a data with a dollar ($) first.
Is there a way to do this without using stored procedure and altering the
data ?
Thanks,
- Pierre
A brief discussion on handling "invalid XML data" is covered here:
http://msdn.microsoft.com/library/de...egram_375f.asp
Check section:
C. Dealing with valid SQL Server characters that are not valid in XML
- good luck,
Geoff -
"Pierre CHALAMET" wrote:

> Hi,
> I wish to insert the following data into an sql table using sqlxml. All
> columns in the table are varchar. The crafted xml is as follow:
> <ROOT xmlns:updg="urn:schemas-microsoft-com:xml-updategram">
> <updg:sync><updg:after>
> <temp_Outstanding drawdownApp="LOA"
> drawdownId="XYZ"
> facilityId="$J5EZEFN">
> </temp_Outstanding>
> </updg:after></updg:sync>
> </ROOT>
> But this lamely fail with the following error: Invalid XML elements found
> inside sync block (HRESULT="0x80004005").
> The code to perform the update is as follow:
> SqlXmlCommand cmd = new SqlXmlCommand(conn);
> cmd.CommandType = SqlXmlCommandType.UpdateGram;
> cmd.CommandText = content;
> stm = cmd.ExecuteStream();
>
> The trouble seems to come from the $J5EZEFN field. Is there a way to insert
> something into a table that begin with a dollar ($) sign ?
> It seems that $XXX is used to pass parameters - but, well, I do not want to
> pass parameter. I just want to insert a data with a dollar ($) first.
> Is there a way to do this without using stored procedure and altering the
> data ?
> Thanks,
> - Pierre
>
|||XXX is perfectly valid in xml and even encoding this as &x36; does not solve
any problem. I strongly believe that $XYZ is reserved for parameter.
Is there a way to disable parameters in this kind of xml ? I just want to
know how to espace dollar ($) when used as 1st char in a field.
- Pierre
"Geoff Ely" wrote:
[vbcol=seagreen]
> A brief discussion on handling "invalid XML data" is covered here:
> http://msdn.microsoft.com/library/de...egram_375f.asp
> Check section:
> C. Dealing with valid SQL Server characters that are not valid in XML
> - good luck,
> Geoff -
> "Pierre CHALAMET" wrote:
|||The problem is that when the Updategram does not have an associated
mapping-schema, the Updategram processor treats the "$" sign as a special
currency symbol and expects a numerical value after it.
As far as I know the workaround is to use a mapping schema.
Thank you,
Amar Nalla [MSFT]
PS: This posting is provided "AS IS" and confers on rights or warranties
"Pierre CHALAMET" <PierreCHALAMET@.discussions.microsoft.com> wrote in
message news:B82E01B2-B043-4E32-9048-ADF49C469805@.microsoft.com...[vbcol=seagreen]
> XXX is perfectly valid in xml and even encoding this as &x36; does not
> solve
> any problem. I strongly believe that $XYZ is reserved for parameter.
> Is there a way to disable parameters in this kind of xml ? I just want to
> know how to espace dollar ($) when used as 1st char in a field.
> - Pierre
>
>
> "Geoff Ely" wrote:
|||I think I could not provide a mapping schema. The reason is that I'm using
BizTalk Server 2004 with an SQL send port (which does use sqlxml behind the
scene).
Since I'm having a bug with an orchestration because of a bad placed dollar
I sadly thought this could be solved easily with the understanding of sqlxml
behaviour.
I'll go back to biztalk server newsgroup so...
- Pierre

How to insert data with dollar ($) first with sqlxml ?

Hi,
I wish to insert the following data into an sql table using sqlxml. All
columns in the table are varchar. The crafted xml is as follow:
<ROOT xmlns:updg="urn:schemas-microsoft-com:xml-updategram">
<updg:sync><updg:after>
<temp_Outstanding drawdownApp="LOA"
drawdownId="XYZ"
facilityId="$J5EZEFN">
</temp_Outstanding>
</updg:after></updg:sync>
</ROOT>
But this lamely fail with the following error: Invalid XML elements found
inside sync block (HRESULT="0x80004005").
The code to perform the update is as follow:
SqlXmlCommand cmd = new SqlXmlCommand(conn);
cmd.CommandType = SqlXmlCommandType.UpdateGram;
cmd.CommandText = content;
stm = cmd.ExecuteStream();
The trouble seems to come from the $J5EZEFN field. Is there a way to insert
something into a table that begin with a dollar ($) sign ?
It seems that $XXX is used to pass parameters - but, well, I do not want to
pass parameter. I just want to insert a data with a dollar ($) first.
Is there a way to do this without using stored procedure and altering the
data ?
Thanks,
- PierreA brief discussion on handling "invalid XML data" is covered here:
http://msdn.microsoft.com/library/d...
egram_375f.asp
Check section:
C. Dealing with valid SQL Server characters that are not valid in XML
- good luck,
Geoff -
"Pierre CHALAMET" wrote:

> Hi,
> I wish to insert the following data into an sql table using sqlxml. All
> columns in the table are varchar. The crafted xml is as follow:
> <ROOT xmlns:updg="urn:schemas-microsoft-com:xml-updategram">
> <updg:sync><updg:after>
> <temp_Outstanding drawdownApp="LOA"
> drawdownId="XYZ"
> facilityId="$J5EZEFN">
> </temp_Outstanding>
> </updg:after></updg:sync>
> </ROOT>
> But this lamely fail with the following error: Invalid XML elements found
> inside sync block (HRESULT="0x80004005").
> The code to perform the update is as follow:
> SqlXmlCommand cmd = new SqlXmlCommand(conn);
> cmd.CommandType = SqlXmlCommandType.UpdateGram;
> cmd.CommandText = content;
> stm = cmd.ExecuteStream();
>
> The trouble seems to come from the $J5EZEFN field. Is there a way to inser
t
> something into a table that begin with a dollar ($) sign ?
> It seems that $XXX is used to pass parameters - but, well, I do not want t
o
> pass parameter. I just want to insert a data with a dollar ($) first.
> Is there a way to do this without using stored procedure and altering the
> data ?
> Thanks,
> - Pierre
>|||XXX is perfectly valid in xml and even encoding this as &x36; does not solve
any problem. I strongly believe that $XYZ is reserved for parameter.
Is there a way to disable parameters in this kind of xml ? I just want to
know how to espace dollar ($) when used as 1st char in a field.
- Pierre
"Geoff Ely" wrote:
> A brief discussion on handling "invalid XML data" is covered here:
> http://msdn.microsoft.com/library/d...tegram_375f.asp
> Check section:
> C. Dealing with valid SQL Server characters that are not valid in XML
> - good luck,
> Geoff -
> "Pierre CHALAMET" wrote:
>|||The problem is that when the Updategram does not have an associated
mapping-schema, the Updategram processor treats the "$" sign as a special
currency symbol and expects a numerical value after it.
As far as I know the workaround is to use a mapping schema.
Thank you,
Amar Nalla [MSFT]
PS: This posting is provided "AS IS" and confers on rights or warranties
"Pierre CHALAMET" <PierreCHALAMET@.discussions.microsoft.com> wrote in
message news:B82E01B2-B043-4E32-9048-ADF49C469805@.microsoft.com...
> XXX is perfectly valid in xml and even encoding this as &x36; does not
> solve
> any problem. I strongly believe that $XYZ is reserved for parameter.
> Is there a way to disable parameters in this kind of xml ? I just want to
> know how to espace dollar ($) when used as 1st char in a field.
> - Pierre
>
>
> "Geoff Ely" wrote:
>|||I think I could not provide a mapping schema. The reason is that I'm using
BizTalk Server 2004 with an SQL send port (which does use sqlxml behind the
scene).
Since I'm having a bug with an orchestration because of a bad placed dollar
I ly thought this could be solved easily with the understanding of sqlxml
behaviour.
I'll go back to biztalk server newsgroup so...
- Pierre

How to insert data into xml column

I want to insert :

<column>
<column_name>feedbackloop</column_name>
<column_type>INT</column_type>
</column>

at the end of the existing xml.

Perhaps it will be easier if i proved the schema and existing xml:

Code Snippet

create xml schema collection email_column_xml_schema as
'<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:t="grs" targetNamespace="grs" elementFormDefault="qualified">
<xsd:element name="object">
<xsd:complexType>
<xsd:complexContent>
<xsd:restriction base="xsd:anyType">
<xsd:sequence>
<xsd:element name="type" type="xsd:string"/>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="remote" type="xsd:integer"/>
<xsd:element name="provider" type="xsd:string" />
<xsd:element name="connectionstring" type="xsd:string" />
<xsd:element name="database_name" type="xsd:string" />
<xsd:element name="send_using" type="xsd:string"/>
<xsd:element name="ftp_server" type="xsd:string" />
<xsd:element name="ftp_user" type="xsd:string" />
<xsd:element name="ftp_password" type="xsd:string" />
<xsd:element name="ftp_port_number" type="xsd:decimal" />
<xsd:element name="message" type="xsd:string" />
<xsd:element name="subject" type="xsd:string" />
<xsd:element name="recipients" type="xsd:string" />
<xsd:element name="as_attachment" type="xsd:integer" />
<xsd:element name="file_name" type="xsd:string" />
<xsd:element name="delimeter" type="xsd:string" />
<xsd:element name="send_interval_days" type="xsd:integer"/>
<xsd:element name="AlwaysSend" type="xsd:integer"/>
<xsd:element name="enabled" type="xsd:integer"/>
<xsd:element name="column" maxOccurs="unbounded">
<xsd:complexType>
<xsd:complexContent>
<xsd:restriction base="xsd:anyType">
<xsd:sequence>
<xsd:element name="column_name" type="xsd:string" />
<xsd:element name="column_type" type="xsd:string" />
</xsd:sequence>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
</xsd:schema>'
go


CREATE TABLE email_column (email_id INT PRIMARY KEY IDENTITY(1,1), xColumn XML(email_column_xml_schema))
go

insert email_column values( '<object xmlns="grs">
<type>VIEW</type>
<name>snapshot</name>
<remote>1</remote>
<provider>SQLNCLI</provider>
<connectionstring></connectionstring>
<database_name></database_name>
<send_using>email</send_using>
<ftp_server></ftp_server>
<ftp_user></ftp_user>
<ftp_password></ftp_password>
<ftp_port_number>0</ftp_port_number>
<message>Snapshot</message>
<subject>Snapshot</subject>
<recipients></recipients>
<as_attachment>0</as_attachment>
<file_name></file_name>
<delimeter></delimeter>
<send_interval_days>1</send_interval_days>
<AlwaysSend>0</AlwaysSend>
<enabled>1</enabled>
<column>
<column_name>day</column_name>
<column_type>DATETIME</column_type>
</column>
<column>
<column_name>domainname</column_name>
<column_type>VARCHAR(50)</column_type>
</column>
<column>
<column_name>ratio</column_name>
<column_type>DECIMAL(10,2)</column_type>
</column>
</object>' )
go

Your schema has a target namespace 'grs' while the XML you are trying to insert has the namespace 'grscorp'. So that sample above does not fit the schema. If I change the XML to have namespace 'grs' then it is possible to insert the XML data. And then the following UPDATE statement works for me to insert the column element:

Code Snippet

UPDATE email_column

SET xColumn.modify('

declare default element namespace "grs";

insert

<column>

<column_name>feedbackloop</column_name>

<column_type>INT</column_type>

</column>

into (/object)[1]

');

|||Smile works perfectly, thanks.

How to insert a xml file in sql server database using asp.net?

hii,

i want to insert a xml file into the sql server using asp.net.can sm1 help me wth d coding part?What server version you use?

In 2005 - there is XML datatype and almost unlimited size of XML.

In 2000 - for character datatype you limited to 8000 characters unless you are going to use text datatype.sql

Monday, March 26, 2012

How to insert a node, with value queried from another node

We're trying to move some of our data between nodes in an XML column.
I basically want to migrate:
FROM
<OldNodeParent>
<OldNode>1234</OldNode>
</OldNodeParent>
TO
<OldNodeParent>
<OldNode>1234</OldNode>
</OldNodeParent>
<NewNode>1234</NewNode>
I was trying something like (which doesn't work):
UPDATE MyTable
SET XmlColumn.modify('
insert <NewNode>(/OldNodeParent/OldNode)[1]</NewNode> as last
into (/)[1]
')
WHERE XmlColumn.exist('/OldNodeParent/OldNode') = 1
AND XmlColumn.exist('/NewNode') = 0
Any ideas on how this could be achieved?
Thanks,
LubdhaTry this
UPDATE MyTable
SET XmlColumn.modify('
insert
if (count(/NewNode) = 0)
then element NewNode {(/OldNodeParent/OldNode/text())[1]}
else ()
as last into (/)[1]
')|||More correctly
UPDATE MyTable
SET XmlColumn.modify('
insert
if ( (/OldNodeParent/OldNode/text()) and not (/NewNode) )
then element NewNode {(/OldNodeParent/OldNode/text())[1]}
else ()
as last into (/)[1]
')|||Wow! That worked like a charm, thanks a lot!

Monday, March 19, 2012

How to import XML file into SQL.

I want to import XML file as the '@.doc' value when I execute 'sp_xml_preparedocument', many thanks!Check out this article:

http://gridviewguy.com/ArticleDetails.aspx?articleID=76

How to import XML

I grabbed the following .xml and .xsd files from an online tutorial, and tried to import them into SQL Server by using XML Source. I want to be able to import ALL the data; however, the simpleType elements under the root <shiporder> are all missing from the XML source, e.g <orderpersion>. The root element, including any attributes from the root element are also missing...e.g <shiporder orderid="889923"

How can I import these missing fields? The .xml and .xsd files are below.

Any help will be greatly appreciated. Thanks.

.XML and .XSD files below. please note that the website replaces ": s" with Tongue Tied

shiporder.xml
-
<?xml version="1.0" encoding="ISO-8859-1"?>

<shiporder orderid="889923"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="shiporder.xsd">
<orderperson>John Smith</orderperson>
<shipto>
<name>Ola Nordmann</name>
<address>Langgt 23</address>
<city>4000 Stavanger</city>
<country>Norway</country>
</shipto>
<item>
<title>Empire Burlesque</title>
<note>Special Edition</note>
<quantity>1</quantity>
<price>10.90</price>
</item>
<item>
<title>Hide your heart</title>
<quantity>1</quantity>
<price>9.90</price>
</item>
</shiporder>
-

shiporder.xsd...
-
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsTongue Tiedchema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xsTongue TiedimpleType name="stringtype">
<xs:restriction base="xsTongue Tiedtring"/>
</xsTongue TiedimpleType>

<xsTongue TiedimpleType name="inttype">
<xs:restriction base="xsStick out tongueositiveInteger"/>
</xsTongue TiedimpleType>

<xsTongue TiedimpleType name="dectype">
<xs:restriction base="xsBig Smileecimal"/>
</xsTongue TiedimpleType>

<xsTongue TiedimpleType name="orderidtype">
<xs:restriction base="xsTongue Tiedtring">
<xsStick out tongueattern value="[0-9]{6}"/>
</xs:restriction>
</xsTongue TiedimpleType>

<xs:complexType name="shiptotype">
<xsTongue Tiedequence>
<xs:element name="name" type="stringtype"/>
<xs:element name="address" type="stringtype"/>
<xs:element name="city" type="stringtype"/>
<xs:element name="country" type="stringtype"/>
</xsTongue Tiedequence>
</xs:complexType>

<xs:complexType name="itemtype">
<xsTongue Tiedequence>
<xs:element name="title" type="stringtype"/>
<xs:element name="note" type="stringtype" minOccurs="0"/>
<xs:element name="quantity" type="inttype"/>
<xs:element name="price" type="dectype"/>
</xsTongue Tiedequence>
</xs:complexType>

<xs:complexType name="shipordertype">
<xsTongue Tiedequence>
<xs:element name="orderperson" type="stringtype"/>
<xs:element name="shipto" type="shiptotype"/>
<xs:element name="item" maxOccurs="unbounded" type="itemtype"/>
</xsTongue Tiedequence>
<xs:attribute name="orderid" type="orderidtype" use="required"/>
</xs:complexType>

<xs:element name="shiporder" type="shipordertype"/>

</xsTongue Tiedchema>

The XML Source expects a dummy root for some reason. Adding one to the XML and XSD should get you what you need.

Code Snippet


<root>
<shiporder orderid="889923"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="shiporder.xsd">
<orderperson>John Smith</orderperson>
<shipto>
<name>Ola Nordmann</name>
<address>Langgt 23</address>
<city>4000 Stavanger</city>
<country>Norway</country>
</shipto>
<item>
<title>Empire Burlesque</title>
<note>Special Edition</note>
<quantity>1</quantity>
<price>10.90</price>
</item>
<item>
<title>Hide your heart</title>
<quantity>1</quantity>
<price>9.90</price>
</item>
</shiporder>
</root>

Code Snippet

<xs:complexType name="roottype">
<xs:sequence>
<xs:element name="shiporder" type="shipordertype"/>
</xs:sequence>
</xs:complexType>

<xs:element name="root" type="roottype"/>

|||

Hey JayH,

That was it. Thanks a lot.

Friday, March 9, 2012

how to import an xml file to sql

I am using 2005 Enterprise and Standard. I need to know to to import an xml
file to both of these.
Thank you
Dee
Look up OPENROWSET in Books Online, specifically - look at the BULK option.
http://msdn2.microsoft.com/en-us/library/ms190312.aspx
ML
Matija Lah, SQL Server MVP
http://milambda.blogspot.com/
|||This is store data and is very large. I was hoping not to write all that
code and do not know how to execute all the applications for Bulk Load. The
xml file may need to be cleaned up as well.
Any further help will be appreciated. I do not know how to use openrowset.
Thank you
Dee
"ML" wrote:

> Look up OPENROWSET in Books Online, specifically - look at the BULK option.
> http://msdn2.microsoft.com/en-us/library/ms190312.aspx
>
> ML
> --
> Matija Lah, SQL Server MVP
> http://milambda.blogspot.com/
|||Have you tried the examples in Books Online?
You could also use SSIS to parse the XML and extract the information you
need, either way - you won't be able to avoid at least a bit of coding.
If you post a sample of the XML (not the whole thing, of course) then we can
help you come up with a more accurate solution.
ML
Matija Lah, SQL Server MVP
http://milambda.blogspot.com/
|||Here is a small example:
<Product Id="-av1011-bass">
<Code>AV1011-FS-BASS</Code>
<Description>Bass Industries Avalon [AV1011-FS-BASS]</Description>
<Url>http://www.bizchair.com/-av1011-bass.html</Url>
<Orderable>NO</Orderable>
<Taxable>NO</Taxable>
<Path>
<ProductRef Id="bass-industries"
Url="http://www.bizchair.com/bass-industries.html">Bass
Industries</ProductRef>
</Path>
<Caption><li>A blend of contemporary edge, softness and
comfort</li><li> A great synergy of design, special relationship and
function</li><li>Life time warranty on frames, springs, and moving
parts</li><li>2 year warranty</li><li><b>Come to BizChair.com for all your
Home Theater Furniture and for all your Home Furniture needs!</b></Caption>
</Product>
<Product Id="-ma1061-bass">
<Code>MA1061-FS-BASS</Code>
<Description>Bass Industries Matinee Lounger
[MA1061-FS-BASS]</Description>
<Url>http://www.bizchair.com/-ma1061-bass.html</Url>
<Orderable>NO</Orderable>
<Taxable>NO</Taxable>
<Path>
<ProductRef Id="bass-industries"
Url="http://www.bizchair.com/bass-industries.html">Bass
Industries</ProductRef>
</Path>
<Caption><li>Available in Black Leather Only</li><li>Straight Row
Only</li><li>Motorized Recline</li><li>Chaise Styling</li><li>Space
Saver</li><li>Life time warranty on all frames, springs and moving
parts</li><li>5 year warranty on leather</li><li>2 year warranty on all other
materials</li><li><b>Come to BizChair.com for all your Home Theater Furniture
and for all your Home Furniture needs!</b></Caption>
</Product>
For books online do I just look for SSIS?
Thanks
Dee
"ML" wrote:

> Have you tried the examples in Books Online?
> You could also use SSIS to parse the XML and extract the information you
> need, either way - you won't be able to avoid at least a bit of coding.
> If you post a sample of the XML (not the whole thing, of course) then we can
> help you come up with a more accurate solution.
>
> ML
> --
> Matija Lah, SQL Server MVP
> http://milambda.blogspot.com/
|||That's nice! Thanks! Now if you'd just post an example of the output you need.
Regarding SSIS - you could start with Books Online. There's also a web site
dedicated to SSIS:
http://www.sqlis.com/
ML
Matija Lah, SQL Server MVP
http://milambda.blogspot.com/
|||We were creating our store in access and we used queries. Our store was
housed on yahoo. We are getting away from the yahoo store and going to
another hosting company that supports SQL.
Here is a line from hone of our queries in access and I that they would like
for it to look the same in SQL but now in queries.
idpathnameabstractcodepricesale-pricecostmap-pricemarginship-weightavailabilityorderabletaxableleafseat-size1arm-heightback-sizecapacitydepthweightexterior-sizeinterior-sizeheightlengthwidthoverall-dimensionsdegree-of-swivelmainbridgereturnsale-price-textseat-depthseat-heightseat-thicknessseat-widthreclinerottomanshipping-infoshipping-optionscolor-optionsdimsdiameterquantity-per-cartonright-columnout-of-stockcustom-orderquickship60-day-guaranteefree-shippingis-top-sellertemplate-numberback-height-from-seatcredenzahutchcustom-optionscontentsoptionalrelated-samplesUserIDcaptionflat-ship-rate1Inside-deliveryshipping-costManufacturermpnUPCISBNASIN-Amazon
Numbercollectionoptionsdeliveryshipping-pricekeywordsproduct-typemade-inage-rangePromoFree-shipping2departmentmaterialsgenderartist-designergreen-certifiedCA
Product SummaryCA Product Short NameCA Promo
Textproduct-urlVendorCompletedUpdated
101cpu-mcoMacoMaco Side Pount CPU Holder [101CPU-MCO]Maco Side Pount CPU
Holder
[101CPU-MCO]101CPU-MCO175.0089.9987.50$0.00FALSETRUEFALSEFALSEFALSEFALSEFALSEFALSEFALSE5"<li>Under
desk side mount design is
expandable in depth only</li><li>Will fit all
brands of furniture</li><li>Keeps your CPU
elevated from dusty floors</li><li>Side
mount onl</li><li>16 gauge steel<\li><li>Perfect for school or library
settings</li><li>20"$0.00Maco Furniture101cpu$0.00steelschool
furniture, office furniture, home furnitureschool,
librarysteelFALSEhttp://www.bizchair.com/BizChair.comFALSE14-Jan-08
Thanks Dee
"ML" wrote:

> That's nice! Thanks! Now if you'd just post an example of the output you need.
> Regarding SSIS - you could start with Books Online. There's also a web site
> dedicated to SSIS:
> http://www.sqlis.com/
>
> ML
> --
> Matija Lah, SQL Server MVP
> http://milambda.blogspot.com/
|||Could you also post the table DDL as the text in your previous post didn't
quite make it accross as you'd expected.
For info on how to do that see this article:
http://www.aspfaq.com/etiquette.asp?id=5006
ML
Matija Lah, SQL Server MVP
http://milambda.blogspot.com/
|||I can't seem to get mine to work.
Thanks
Dee
"ML" wrote:

> Could you also post the table DDL as the text in your previous post didn't
> quite make it accross as you'd expected.
> For info on how to do that see this article:
> http://www.aspfaq.com/etiquette.asp?id=5006
>
> ML
> --
> Matija Lah, SQL Server MVP
> http://milambda.blogspot.com/
|||What doesn't seem to work?
Ok. I fixed your XML (it was not well-formed):
<?xml version="1.0" encoding="UTF-8"?>
<Products>
<Product Id="-av1011-bass">
<Code>AV1011-FS-BASS</Code>
<Description>Bass Industries Avalon [AV1011-FS-BASS]</Description>
<Url>http://www.bizchair.com/-av1011-bass.html</Url>
<Orderable>NO</Orderable>
<Taxable>NO</Taxable>
<Path>
<ProductRef Id="bass-industries"
Url="http://www.bizchair.com/bass-industries.html">Bass
Industries</ProductRef>
</Path>
<Caption>
<li>A blend of contemporary edge, softness and
comfort</li>
<li>A great synergy of design, special relationship and
function</li>
<li>Life time warranty on frames, springs, and moving
parts</li>
<li>2 year warranty</li>
<li>
<b>Come to BizChair.com for all your
Home Theater Furniture and for all your Home Furniture needs!</b>
</li>
</Caption>
</Product>
<Product Id="-ma1061-bass">
<Code>MA1061-FS-BASS</Code>
<Description>Bass Industries Matinee Lounger
[MA1061-FS-BASS]</Description>
<Url>http://www.bizchair.com/-ma1061-bass.html</Url>
<Orderable>NO</Orderable>
<Taxable>NO</Taxable>
<Path>
<ProductRef Id="bass-industries"
Url="http://www.bizchair.com/bass-industries.html">Bass
Industries</ProductRef>
</Path>
<Caption>
<li>Available in Black Leather Only</li>
<li>Straight Row
Only</li>
<li>Motorized Recline</li>
<li>Chaise Styling</li>
<li>Space
Saver</li>
<li>Life time warranty on all frames, springs and moving
parts</li>
<li>5 year warranty on leather</li>
<li>2 year warranty on all other
materials</li>
<li>
<b>Come to BizChair.com for all your Home Theater Furniture
and for all your Home Furniture needs!</b>
</li>
</Caption>
</Product>
</Products>
Save it to a folder (in my case that's "D:\Temp\Products.xml" - referenced
in the OPENROWSET function).
Then execute this example:
declare@.xmlvarchar(max)
declare@.xmlHandleint
-- Bulk load the xml from the file
set@.xml = (
select*
fromopenrowset
(
bulk'D:\Temp\Products.xml'
,single_blob
) Products
)
-- Prepare the DOM document
execsp_xml_preparedocument
@.xmlHandle output
,@.xml
-- Parse the XML
-- You can include this select statement in your insert statement
select*
fromopenxml
(
@.xmlHandle
,'/Products/Product'
)
with(
idvarchar(32)'@.Id'
,codevarchar(32)'Code'
,[description]varchar(1024)'Description'
,urlvarchar(1024)'Url'
,orderablevarchar(3)'NO'
,taxablevarchar(3)'NO'
,[path]varchar(1024)'Path'
,captionvarchar(1024)'Caption'
)
-- Never forget to remove the DOM document as soon as you're done using it.
execsp_xml_removedocument
@.xmlHandle
go
Let us know how you get along.
ML
Matija Lah, SQL Server MVP
http://milambda.blogspot.com/

How to import a XSD and XML file into a SQL table

I have generated the output of a SQL query against Northwind in the
form of the XSD and the XML file for a query using the following query:
For generating the XML output:
SELECT * FROM Customers
FOR XML AUTO
Similarly, I use the following query to generate a XSD output of the
above query from the Northwind database:
SELECT * FROM Customers
WHERE 1 = 0
FOR XML AUTO, ELEMENTS, XMLDATA
Now I have the dump of the customers table in a XSD and XML format I
want to import the data in the resulting table into another database
using DTS or whatever to interpre the .XSD and the .XML files.
Please share the code to import a arbitrary .XML and .XSD file into a
SQL table and the meta data SQL must determine dynamically to create a
table in the target database.
Thanks
KarenDownload SQLXML 3.0
(http://www.microsoft.com/downloads/...&DisplayLang=en)
and read the documentation on the XML Bulk Load component. It's a COM
component you can call from a script (such as a .vbs) that will import data
from an XML file into a SQL Server database based on the mappings defined in
a schema.
Cheers,
Graeme
--
Graeme Malcolm
Principal Technologist
Content Master
- a member of CM Group Ltd.
www.contentmaster.com
<karenmiddleol@.yahoo.com> wrote in message
news:1116579889.377764.305650@.g44g2000cwa.googlegroups.com...
I have generated the output of a SQL query against Northwind in the
form of the XSD and the XML file for a query using the following query:
For generating the XML output:
SELECT * FROM Customers
FOR XML AUTO
Similarly, I use the following query to generate a XSD output of the
above query from the Northwind database:
SELECT * FROM Customers
WHERE 1 = 0
FOR XML AUTO, ELEMENTS, XMLDATA
Now I have the dump of the customers table in a XSD and XML format I
want to import the data in the resulting table into another database
using DTS or whatever to interpre the .XSD and the .XML files.
Please share the code to import a arbitrary .XML and .XSD file into a
SQL table and the meta data SQL must determine dynamically to create a
table in the target database.
Thanks
Karen|||http://msdn.microsoft.com/library/d... />
sqlxml.asp
Download the sample code, project for this article as well as reading it...
One of the sample projects shows the nearly exaclty the code you inquired
about...|||Just a clarification: XMLDATA does not generate an XSD but an XDR file. You
have to use a mid-tier tool that converts the XDR into XSD if you really
need an XSD (or use SQL Server 2005 where you can specify XMLSCHEMA to get
an XSD).
Best regards
Michael
<karenmiddleol@.yahoo.com> wrote in message
news:1116579889.377764.305650@.g44g2000cwa.googlegroups.com...
>I have generated the output of a SQL query against Northwind in the
> form of the XSD and the XML file for a query using the following query:
> For generating the XML output:
> SELECT * FROM Customers
> FOR XML AUTO
> Similarly, I use the following query to generate a XSD output of the
> above query from the Northwind database:
> SELECT * FROM Customers
> WHERE 1 = 0
> FOR XML AUTO, ELEMENTS, XMLDATA
>
> Now I have the dump of the customers table in a XSD and XML format I
> want to import the data in the resulting table into another database
> using DTS or whatever to interpre the .XSD and the .XML files.
> Please share the code to import a arbitrary .XML and .XSD file into a
> SQL table and the meta data SQL must determine dynamically to create a
> table in the target database.
> Thanks
> Karen
>|||Anyone knows how to dump the result of the XML AUTO query to an XML
file?
I have a query and used bcp to dump it and i named it with an XML
extension. If the result dump is very short like 3 records only. It
is displaying OK when I try to opien it in IE Browser. But when the
result of my BCP dump is big.. it is producing an error. The thing is,
If I executr my query directly over the Browser (using HTTP with my
database tied up to a Virtual Directory in IIS), It is displaying all
the right results.
Can anyone help me on this? I just need to dump the XML result into a
file so it can be archived and viewed.
Thanks,
Jeff
pongaski
---
Posted via http://www.mcse.ms
---
View this thread: http://www.mcse.ms/message1626243.html|||Programmatically, you should use ADO or ADO.Net to write the FOR XML result
into the file stream. Alternatively, you can use the HTTP access through the
virtual directory and use view source, save as to save it...
Best regards
Michael
"pongaski" <pongaski.1pudhz@.mail.mcse.ms> wrote in message
news:pongaski.1pudhz@.mail.mcse.ms...
> Anyone knows how to dump the result of the XML AUTO query to an XML
> file?
> I have a query and used bcp to dump it and i named it with an XML
> extension. If the result dump is very short like 3 records only. It
> is displaying OK when I try to opien it in IE Browser. But when the
> result of my BCP dump is big.. it is producing an error. The thing is,
> If I executr my query directly over the Browser (using HTTP with my
> database tied up to a Virtual Directory in IIS), It is displaying all
> the right results.
> Can anyone help me on this? I just need to dump the XML result into a
> file so it can be archived and viewed.
> Thanks,
> Jeff
>
> --
> pongaski
> ---
> Posted via http://www.mcse.ms
> ---
> View this thread: http://www.mcse.ms/message1626243.html
>|||"Michael Rys [MSFT]" wrote:

> Programmatically, you should use ADO or ADO.Net to write the FOR XML resul
t
> into the file stream. Alternatively, you can use the HTTP access through t
he
> virtual directory and use view source, save as to save it...
> Best regards
> Michael
It is not true. Lower I write stored proc wich write result "FOR XML" query
to txt file.
CREATE PROCEDURE usp_SQLtoXMLfile (
@.sqlXmlQuerryInput NVARCHAR(4000), --Query text with FOR XML
@.FileNameInput varchar(255), --File name with full path
@.headInput nvarchar(4000), --Prefix expression in result file
@.sufixInput nvarchar(4000) --postfix expression in result file
) AS
DECLARE @.FileName varchar(255) --\
DECLARE @.Text1 nvarchar(4000) --|
DECLARE @.FS int --|
DECLARE @.OLEResult int -- \
DECLARE @.FileID int -- /The bloc variables for work with files
DECLARE @.hr int --|
DECLARE @.source varchar(30) --|
DECLARE @.desc varchar (200) --/
DECLARE @.text NVARCHAR(4000) --bufer only
declare @.cur_edit cursor
declare @._kfvalue sql_variant --Return value
DECLARE @.sqlXmlQuerry NVARCHAR(4000) --Variable for query
BEGIN
----
--
EXECUTE @.OLEResult = sp_OACreate 'Scripting.FileSystemObject', @.FS
OUTPUT --create object for work with file system
IF @.OLEResult <> 0 --chek errors
BEGIN
PRINT 'Scripting.FileSystemObject'
GOTO Error_Handler
END
SET @.FileName=@.FileNameInput
execute @.OLEResult = sp_OAMethod @.FS,'CreateTextFile',@.FileID OUTPUT,
@.FileName --Create text file
IF @.OLEResult <> 0
BEGIN
PRINT 'CreateTextFile'
GOTO Error_Handler
END
----
--
IF LEN(@.headInput)>0 --Check prefix empty
BEGIN
execute @.OLEResult = sp_OAMethod @.FileID, 'WriteLine', NULL, @.headInput
--Write to text file prefix
IF @.OLEResult <> 0
BEGIN
PRINT 'WriteLine'
GOTO Error_Handler
END
END
----
--
SET @.sqlXmlQuerry=@.sqlXmlQuerryInput --Query text
SET @.sqlXmlQuerry=' SELECT * FROM OPENROWSET(''MSDASQL'',''DRIVER={SQL
Server};SERVER='+@.@.SERVERNAME+''','''+@.s
qlXmlQuerry+''') ' --Adapt query for
cursor
SET @.sqlXmlQuerry=' set @.cur_edit = CURSOR STATIC FOR '+@.sqlXmlQuerry+' open
@.cur_edit ' --Add to query string declaration and opening cursor
--PRINT @.sqlXmlQuerry --for debug
exec sp_executesql @.sqlXmlQuerry, N'@.cur_edit cursor output, @._kfvalue
sql_variant', @.cur_edit output, @._kfvalue --Execute the string
FETCH NEXT FROM @.cur_edit INTO @.text --Return from cursor
WHILE (@.@.fetch_status = 0)
BEGIN
----
--
execute @.OLEResult = sp_OAMethod @.FileID, 'Write', NULL, @.text --Add to
text file value from @.text
IF @.OLEResult <> 0
BEGIN
PRINT 'WriteLine'
GOTO Error_Handler
END
FETCH NEXT FROM @.cur_edit INTO @.text
END
CLOSE @.cur_edit
DEALLOCATE @.cur_edit
----
--
IF LEN(@.sufixInput)>0 --If variable with postfix expression not empty
BEGIN
execute @.OLEResult = sp_OAMethod @.FileID, 'Write', NULL, @.sufixInput
--Write postfix expression to text file
IF @.OLEResult <> 0
BEGIN
PRINT 'WriteLine'
GOTO Error_Handler
END
END
----
--goto Done
Error_Handler:
PRINT '*** ERROR ***'
EXEC @.hr = sp_OAGetErrorInfo null, @.source OUT, @.desc OUT
SELECT hr = CONVERT (binary(4), @.hr), source = @.source, description = @.desc
Done:
EXECUTE @.OLEResult = sp_OADestroy @.FileID
EXECUTE @.OLEResult = sp_OADestroy @.FS
END
GO
PS Sorry for my english...|||You can use sp_OA stored procs, but it is not something that I recommend
(note that I say "should" and not "it is the only way" :-)).
Thanks for the posting though and no worries about the English. TSQL crosses
language-boundaries :-)
Michael
"Serbat_Ivan" <SerbatIvan@.discussions.microsoft.com> wrote in message
news:C525C398-29B0-4FF1-A494-29D6B61CD66E@.microsoft.com...
> "Michael Rys [MSFT]" wrote:
>
> It is not true. Lower I write stored proc wich write result "FOR XML"
> query
> to txt file.
> CREATE PROCEDURE usp_SQLtoXMLfile (
> @.sqlXmlQuerryInput NVARCHAR(4000), --Query text with FOR XML
> @.FileNameInput varchar(255), --File name with full path
> @.headInput nvarchar(4000), --Prefix expression in result file
> @.sufixInput nvarchar(4000) --postfix expression in result file
> ) AS
> DECLARE @.FileName varchar(255) --\
> DECLARE @.Text1 nvarchar(4000) --|
> DECLARE @.FS int --|
> DECLARE @.OLEResult int -- \
> DECLARE @.FileID int -- /The bloc variables for work with files
> DECLARE @.hr int --|
> DECLARE @.source varchar(30) --|
> DECLARE @.desc varchar (200) --/
> DECLARE @.text NVARCHAR(4000) --bufer only
> declare @.cur_edit cursor
> declare @._kfvalue sql_variant --Return value
> DECLARE @.sqlXmlQuerry NVARCHAR(4000) --Variable for query
> BEGIN
> ----
--
> EXECUTE @.OLEResult = sp_OACreate 'Scripting.FileSystemObject', @.FS
> OUTPUT --create object for work with file system
> IF @.OLEResult <> 0 --chek errors
> BEGIN
> PRINT 'Scripting.FileSystemObject'
> GOTO Error_Handler
> END
> SET @.FileName=@.FileNameInput
> execute @.OLEResult = sp_OAMethod @.FS,'CreateTextFile',@.FileID OUTPUT,
> @.FileName --Create text file
> IF @.OLEResult <> 0
> BEGIN
> PRINT 'CreateTextFile'
> GOTO Error_Handler
> END
> ----
--
> IF LEN(@.headInput)>0 --Check prefix empty
> BEGIN
> execute @.OLEResult = sp_OAMethod @.FileID, 'WriteLine', NULL, @.headInput
> --Write to text file prefix
> IF @.OLEResult <> 0
> BEGIN
> PRINT 'WriteLine'
> GOTO Error_Handler
> END
> END
> ----
--
> SET @.sqlXmlQuerry=@.sqlXmlQuerryInput --Query text
> SET @.sqlXmlQuerry=' SELECT * FROM OPENROWSET(''MSDASQL'',''DRIVER={SQL
> Server};SERVER='+@.@.SERVERNAME+''','''+@.s
qlXmlQuerry+''') ' --Adapt query
> for
> cursor
> SET @.sqlXmlQuerry=' set @.cur_edit = CURSOR STATIC FOR '+@.sqlXmlQuerry+'
> open
> @.cur_edit ' --Add to query string declaration and opening cursor
> --PRINT @.sqlXmlQuerry --for debug
> exec sp_executesql @.sqlXmlQuerry, N'@.cur_edit cursor output, @._kfvalue
> sql_variant', @.cur_edit output, @._kfvalue --Execute the string
> FETCH NEXT FROM @.cur_edit INTO @.text --Return from cursor
> WHILE (@.@.fetch_status = 0)
> BEGIN
> ----
--
> execute @.OLEResult = sp_OAMethod @.FileID, 'Write', NULL, @.text --Add
> to
> text file value from @.text
> IF @.OLEResult <> 0
> BEGIN
> PRINT 'WriteLine'
> GOTO Error_Handler
> END
> FETCH NEXT FROM @.cur_edit INTO @.text
> END
> CLOSE @.cur_edit
> DEALLOCATE @.cur_edit
> ----
--
> IF LEN(@.sufixInput)>0 --If variable with postfix expression not empty
> BEGIN
> execute @.OLEResult = sp_OAMethod @.FileID, 'Write', NULL, @.sufixInput
> --Write postfix expression to text file
> IF @.OLEResult <> 0
> BEGIN
> PRINT 'WriteLine'
> GOTO Error_Handler
> END
> END
> ----
--goto
> Done
> Error_Handler:
> PRINT '*** ERROR ***'
> EXEC @.hr = sp_OAGetErrorInfo null, @.source OUT, @.desc OUT
> SELECT hr = CONVERT (binary(4), @.hr), source = @.source, description =
> @.desc
> Done:
> EXECUTE @.OLEResult = sp_OADestroy @.FileID
> EXECUTE @.OLEResult = sp_OADestroy @.FS
> END
> GO
>
> PS Sorry for my english...
>|||"Michael Rys [MSFT]" wrote:
> You can use sp_OA stored procs, but it is not something that I recommend
> (note that I say "should" and not "it is the only way" :-)).

> Thanks for the posting though and no worries about the English. TSQL cross
es
> language-boundaries :-)
> Michael
You right of all points of course ;)
Why you not recommend use sp_OA stored procs? I know, it is not TSQL in pure
form, but it is one of ways to to solve the problem... Can you describe a
problems wich may appear?|||It is very easy to shoot yourself into the foot and corrupt the server if
you are not careful.
And it has many not so clear interactions (thread safety, memory etc) that
you need to be aware of.
So this is clearly black-belt territory.
Finally, I rather have us provide solutions to these problems instead of
letting us say: "Oh, but sp_OA stored procs can do it" :-).
Best regards
Michael
"Serbat_Ivan" <SerbatIvan@.discussions.microsoft.com> wrote in message
news:E3855E10-23B3-43EA-A416-B743C71E2E0E@.microsoft.com...
> "Michael Rys [MSFT]" wrote:
>
> You right of all points of course ;)
> Why you not recommend use sp_OA stored procs? I know, it is not TSQL in
> pure
> form, but it is one of ways to to solve the problem... Can you describe a
> problems wich may appear?

How to import a XSD and XML file into a SQL table

I have generated the output of a SQL query against Northwind in the
form of the XSD and the XML file for a query using the following query:
For generating the XML output:
SELECT * FROM Customers
FOR XML AUTO
Similarly, I use the following query to generate a XSD output of the
above query from the Northwind database:
SELECT * FROM Customers
WHERE 1 = 0
FOR XML AUTO, ELEMENTS, XMLDATA
Now I have the dump of the customers table in a XSD and XML format I
want to import the data in the resulting table into another database
using DTS or whatever to interpre the .XSD and the .XML files.
Please share the code to import a arbitrary .XML and .XSD file into a
SQL table and the meta data SQL must determine dynamically to create a
table in the target database.
Thanks
Karen
Download SQLXML 3.0
(http://www.microsoft.com/downloads/d...DisplayLang=en)
and read the documentation on the XML Bulk Load component. It's a COM
component you can call from a script (such as a .vbs) that will import data
from an XML file into a SQL Server database based on the mappings defined in
a schema.
Cheers,
Graeme
Graeme Malcolm
Principal Technologist
Content Master
- a member of CM Group Ltd.
www.contentmaster.com
<karenmiddleol@.yahoo.com> wrote in message
news:1116579889.377764.305650@.g44g2000cwa.googlegr oups.com...
I have generated the output of a SQL query against Northwind in the
form of the XSD and the XML file for a query using the following query:
For generating the XML output:
SELECT * FROM Customers
FOR XML AUTO
Similarly, I use the following query to generate a XSD output of the
above query from the Northwind database:
SELECT * FROM Customers
WHERE 1 = 0
FOR XML AUTO, ELEMENTS, XMLDATA
Now I have the dump of the customers table in a XSD and XML format I
want to import the data in the resulting table into another database
using DTS or whatever to interpre the .XSD and the .XML files.
Please share the code to import a arbitrary .XML and .XSD file into a
SQL table and the meta data SQL must determine dynamically to create a
table in the target database.
Thanks
Karen
|||http://msdn.microsoft.com/library/de...exchsqlxml.asp
Download the sample code, project for this article as well as reading it...
One of the sample projects shows the nearly exaclty the code you inquired
about...
|||Just a clarification: XMLDATA does not generate an XSD but an XDR file. You
have to use a mid-tier tool that converts the XDR into XSD if you really
need an XSD (or use SQL Server 2005 where you can specify XMLSCHEMA to get
an XSD).
Best regards
Michael
<karenmiddleol@.yahoo.com> wrote in message
news:1116579889.377764.305650@.g44g2000cwa.googlegr oups.com...
>I have generated the output of a SQL query against Northwind in the
> form of the XSD and the XML file for a query using the following query:
> For generating the XML output:
> SELECT * FROM Customers
> FOR XML AUTO
> Similarly, I use the following query to generate a XSD output of the
> above query from the Northwind database:
> SELECT * FROM Customers
> WHERE 1 = 0
> FOR XML AUTO, ELEMENTS, XMLDATA
>
> Now I have the dump of the customers table in a XSD and XML format I
> want to import the data in the resulting table into another database
> using DTS or whatever to interpre the .XSD and the .XML files.
> Please share the code to import a arbitrary .XML and .XSD file into a
> SQL table and the meta data SQL must determine dynamically to create a
> table in the target database.
> Thanks
> Karen
>
|||Anyone knows how to dump the result of the XML AUTO query to an XML file?
I have a query and used bcp to dump it and i named it with an XML extension. If the result dump is very short like 3 records only. It is displaying OK when I try to opien it in IE Browser. But when the result of my BCP dump is big.. it is producing an error. The thing is, If I executr my query directly over the Browser (using HTTP with my database tied up to a Virtual Directory in IIS), It is displaying all the right results.
Can anyone help me on this? I just need to dump the XML result into a file so it can be archived and viewed.
Thanks,
Jeff|||Programmatically, you should use ADO or ADO.Net to write the FOR XML result
into the file stream. Alternatively, you can use the HTTP access through the
virtual directory and use view source, save as to save it...
Best regards
Michael
"pongaski" <pongaski.1pudhz@.mail.mcse.ms> wrote in message
news:pongaski.1pudhz@.mail.mcse.ms...
> Anyone knows how to dump the result of the XML AUTO query to an XML
> file?
> I have a query and used bcp to dump it and i named it with an XML
> extension. If the result dump is very short like 3 records only. It
> is displaying OK when I try to opien it in IE Browser. But when the
> result of my BCP dump is big.. it is producing an error. The thing is,
> If I executr my query directly over the Browser (using HTTP with my
> database tied up to a Virtual Directory in IIS), It is displaying all
> the right results.
> Can anyone help me on this? I just need to dump the XML result into a
> file so it can be archived and viewed.
> Thanks,
> Jeff
>
> --
> pongaski
> Posted via http://www.mcse.ms
> View this thread: http://www.mcse.ms/message1626243.html
>
|||"Michael Rys [MSFT]" wrote:

> Programmatically, you should use ADO or ADO.Net to write the FOR XML result
> into the file stream. Alternatively, you can use the HTTP access through the
> virtual directory and use view source, save as to save it...
> Best regards
> Michael
It is not true. Lower I write stored proc wich write result "FOR XML" query
to txt file.
CREATE PROCEDURE usp_SQLtoXMLfile (
@.sqlXmlQuerryInput NVARCHAR(4000), --Query text with FOR XML
@.FileNameInput varchar(255), --File name with full path
@.headInput nvarchar(4000), --Prefix expression in result file
@.sufixInput nvarchar(4000) --postfix expression in result file
) AS
DECLARE @.FileName varchar(255)--\
DECLARE @.Text1 nvarchar(4000)--|
DECLARE @.FS int --|
DECLARE @.OLEResult int -- \
DECLARE @.FileID int -- /The bloc variables for work with files
DECLARE @.hr int--|
DECLARE @.source varchar(30)--|
DECLARE @.desc varchar (200)--/
DECLARE @.text NVARCHAR(4000)--bufer only
declare @.cur_edit cursor
declare @._kfvalue sql_variant--Return value
DECLARE @.sqlXmlQuerry NVARCHAR(4000)--Variable for query
BEGIN
EXECUTE @.OLEResult = sp_OACreate 'Scripting.FileSystemObject', @.FS
OUTPUT--create object for work with file system
IF @.OLEResult <> 0 --chek errors
BEGIN
PRINT 'Scripting.FileSystemObject'
GOTO Error_Handler
END
SET @.FileName=@.FileNameInput
execute @.OLEResult = sp_OAMethod @.FS,'CreateTextFile',@.FileID OUTPUT,
@.FileName --Create text file
IF @.OLEResult <> 0
BEGIN
PRINT 'CreateTextFile'
GOTO Error_Handler
END
-----
IF LEN(@.headInput)>0 --Check prefix empty
BEGIN
execute @.OLEResult = sp_OAMethod @.FileID, 'WriteLine', NULL, @.headInput
--Write to text file prefix
IF @.OLEResult <> 0
BEGIN
PRINT 'WriteLine'
GOTO Error_Handler
END
END
-----
SET @.sqlXmlQuerry=@.sqlXmlQuerryInput --Query text
SET @.sqlXmlQuerry=' SELECT * FROM OPENROWSET(''MSDASQL'',''DRIVER={SQL
Server};SERVER='+@.@.SERVERNAME+''','''+@.sqlXmlQuerr y+''') '--Adapt query for
cursor
SET @.sqlXmlQuerry=' set @.cur_edit = CURSOR STATIC FOR '+@.sqlXmlQuerry+' open
@.cur_edit ' --Add to query string declaration and opening cursor
--PRINT @.sqlXmlQuerry --for debug
exec sp_executesql @.sqlXmlQuerry, N'@.cur_edit cursor output, @._kfvalue
sql_variant', @.cur_edit output, @._kfvalue --Execute the string
FETCH NEXT FROM @.cur_edit INTO @.text --Return from cursor
WHILE (@.@.fetch_status = 0)
BEGIN
-----
execute @.OLEResult = sp_OAMethod @.FileID, 'Write', NULL, @.text --Add to
text file value from @.text
IF @.OLEResult <> 0
BEGIN
PRINT 'WriteLine'
GOTO Error_Handler
END
FETCH NEXT FROM @.cur_edit INTO @.text
END
CLOSE @.cur_edit
DEALLOCATE @.cur_edit
-----
IF LEN(@.sufixInput)>0 --If variable with postfix expression not empty
BEGIN
execute @.OLEResult = sp_OAMethod @.FileID, 'Write', NULL, @.sufixInput
--Write postfix expression to text file
IF @.OLEResult <> 0
BEGIN
PRINT 'WriteLine'
GOTO Error_Handler
END
END
-----goto Done
Error_Handler:
PRINT '*** ERROR ***'
EXEC @.hr = sp_OAGetErrorInfo null, @.source OUT, @.desc OUT
SELECT hr = CONVERT (binary(4), @.hr), source = @.source, description = @.desc
Done:
EXECUTE @.OLEResult = sp_OADestroy @.FileID
EXECUTE @.OLEResult = sp_OADestroy @.FS
END
GO
PS Sorry for my english...
|||You can use sp_OA stored procs, but it is not something that I recommend
(note that I say "should" and not "it is the only way" :-)).
Thanks for the posting though and no worries about the English. TSQL crosses
language-boundaries :-)
Michael
"Serbat_Ivan" <SerbatIvan@.discussions.microsoft.com> wrote in message
news:C525C398-29B0-4FF1-A494-29D6B61CD66E@.microsoft.com...
> "Michael Rys [MSFT]" wrote:
> It is not true. Lower I write stored proc wich write result "FOR XML"
> query
> to txt file.
> CREATE PROCEDURE usp_SQLtoXMLfile (
> @.sqlXmlQuerryInput NVARCHAR(4000), --Query text with FOR XML
> @.FileNameInput varchar(255), --File name with full path
> @.headInput nvarchar(4000), --Prefix expression in result file
> @.sufixInput nvarchar(4000) --postfix expression in result file
> ) AS
> DECLARE @.FileName varchar(255) --\
> DECLARE @.Text1 nvarchar(4000) --|
> DECLARE @.FS int --|
> DECLARE @.OLEResult int -- \
> DECLARE @.FileID int -- /The bloc variables for work with files
> DECLARE @.hr int --|
> DECLARE @.source varchar(30) --|
> DECLARE @.desc varchar (200) --/
> DECLARE @.text NVARCHAR(4000) --bufer only
> declare @.cur_edit cursor
> declare @._kfvalue sql_variant --Return value
> DECLARE @.sqlXmlQuerry NVARCHAR(4000) --Variable for query
> BEGIN
> ----
> EXECUTE @.OLEResult = sp_OACreate 'Scripting.FileSystemObject', @.FS
> OUTPUT --create object for work with file system
> IF @.OLEResult <> 0 --chek errors
> BEGIN
> PRINT 'Scripting.FileSystemObject'
> GOTO Error_Handler
> END
> SET @.FileName=@.FileNameInput
> execute @.OLEResult = sp_OAMethod @.FS,'CreateTextFile',@.FileID OUTPUT,
> @.FileName --Create text file
> IF @.OLEResult <> 0
> BEGIN
> PRINT 'CreateTextFile'
> GOTO Error_Handler
> END
> -----
> IF LEN(@.headInput)>0 --Check prefix empty
> BEGIN
> execute @.OLEResult = sp_OAMethod @.FileID, 'WriteLine', NULL, @.headInput
> --Write to text file prefix
> IF @.OLEResult <> 0
> BEGIN
> PRINT 'WriteLine'
> GOTO Error_Handler
> END
> END
> -----
> SET @.sqlXmlQuerry=@.sqlXmlQuerryInput --Query text
> SET @.sqlXmlQuerry=' SELECT * FROM OPENROWSET(''MSDASQL'',''DRIVER={SQL
> Server};SERVER='+@.@.SERVERNAME+''','''+@.sqlXmlQuerr y+''') ' --Adapt query
> for
> cursor
> SET @.sqlXmlQuerry=' set @.cur_edit = CURSOR STATIC FOR '+@.sqlXmlQuerry+'
> open
> @.cur_edit ' --Add to query string declaration and opening cursor
> --PRINT @.sqlXmlQuerry --for debug
> exec sp_executesql @.sqlXmlQuerry, N'@.cur_edit cursor output, @._kfvalue
> sql_variant', @.cur_edit output, @._kfvalue --Execute the string
> FETCH NEXT FROM @.cur_edit INTO @.text --Return from cursor
> WHILE (@.@.fetch_status = 0)
> BEGIN
> -----
> execute @.OLEResult = sp_OAMethod @.FileID, 'Write', NULL, @.text --Add
> to
> text file value from @.text
> IF @.OLEResult <> 0
> BEGIN
> PRINT 'WriteLine'
> GOTO Error_Handler
> END
> FETCH NEXT FROM @.cur_edit INTO @.text
> END
> CLOSE @.cur_edit
> DEALLOCATE @.cur_edit
> -----
> IF LEN(@.sufixInput)>0 --If variable with postfix expression not empty
> BEGIN
> execute @.OLEResult = sp_OAMethod @.FileID, 'Write', NULL, @.sufixInput
> --Write postfix expression to text file
> IF @.OLEResult <> 0
> BEGIN
> PRINT 'WriteLine'
> GOTO Error_Handler
> END
> END
> -----goto
> Done
> Error_Handler:
> PRINT '*** ERROR ***'
> EXEC @.hr = sp_OAGetErrorInfo null, @.source OUT, @.desc OUT
> SELECT hr = CONVERT (binary(4), @.hr), source = @.source, description =
> @.desc
> Done:
> EXECUTE @.OLEResult = sp_OADestroy @.FileID
> EXECUTE @.OLEResult = sp_OADestroy @.FS
> END
> GO
>
> PS Sorry for my english...
>
|||"Michael Rys [MSFT]" wrote:
> You can use sp_OA stored procs, but it is not something that I recommend
> (note that I say "should" and not "it is the only way" :-)).

> Thanks for the posting though and no worries about the English. TSQL crosses
> language-boundaries :-)
> Michael
You right of all points of course ;)
Why you not recommend use sp_OA stored procs? I know, it is not TSQL in pure
form, but it is one of ways to to solve the problem... Can you describe a
problems wich may appear?
|||It is very easy to shoot yourself into the foot and corrupt the server if
you are not careful.
And it has many not so clear interactions (thread safety, memory etc) that
you need to be aware of.
So this is clearly black-belt territory.
Finally, I rather have us provide solutions to these problems instead of
letting us say: "Oh, but sp_OA stored procs can do it" :-).
Best regards
Michael
"Serbat_Ivan" <SerbatIvan@.discussions.microsoft.com> wrote in message
news:E3855E10-23B3-43EA-A416-B743C71E2E0E@.microsoft.com...
> "Michael Rys [MSFT]" wrote:
>
> You right of all points of course ;)
> Why you not recommend use sp_OA stored procs? I know, it is not TSQL in
> pure
> form, but it is one of ways to to solve the problem... Can you describe a
> problems wich may appear?

Sunday, February 19, 2012

How to I load XML into SQL Server 2000

I feel like I must be missing something because there
doesn't seem to be a simple solution to this problem. I
have an XML document and a DTD document and I want to load
this information into SQL Server.
I try to use DTS import but I keep getting the error
message "SQLOLEDB must be specified as the data provider".
Am I asking too much here?Bob: This can be accomplished using OPENXML in SQL 2000:
http://www.sqlxml.org/faqs.aspx?faq=39.
Jay Nathan
http://www.jaynathan.com/blog
"Bob Smith" <anonymous@.discussions.microsoft.com> wrote in message
news:10ca01c4e54a$cdc35e10$a401280a@.phx.gbl...
> I feel like I must be missing something because there
> doesn't seem to be a simple solution to this problem. I
> have an XML document and a DTD document and I want to load
> this information into SQL Server.
> I try to use DTS import but I keep getting the error
> message "SQLOLEDB must be specified as the data provider".
> Am I asking too much here?

How to I load XML into SQL Server 2000

I feel like I must be missing something because there
doesn't seem to be a simple solution to this problem. I
have an XML document and a DTD document and I want to load
this information into SQL Server.
I try to use DTS import but I keep getting the error
message "SQLOLEDB must be specified as the data provider".
Am I asking too much here?
Bob: This can be accomplished using OPENXML in SQL 2000:
http://www.sqlxml.org/faqs.aspx?faq=39.
Jay Nathan
http://www.jaynathan.com/blog
"Bob Smith" <anonymous@.discussions.microsoft.com> wrote in message
news:10ca01c4e54a$cdc35e10$a401280a@.phx.gbl...
> I feel like I must be missing something because there
> doesn't seem to be a simple solution to this problem. I
> have an XML document and a DTD document and I want to load
> this information into SQL Server.
> I try to use DTS import but I keep getting the error
> message "SQLOLEDB must be specified as the data provider".
> Am I asking too much here?