Solved

How to force an empty XML tag to be loaded into DB table as an empty string

Posted on 2009-07-13
3
345 Views
Last Modified: 2013-11-05
Hi all

I am not sure whether this is an SQL question or an XML question but I have a VB6 application that takes data in an XML file and loads it into a database table using an SQLXMLBulkLoad object.

It does it with issue except for the fact that tags that are empty i.e. have no value get inserted into tha DB table as NULLS and I want them to be empty strings.
 So for example if I have the following XML
<Address1>15 Peters Street</Address1>
<Address2>Hobble End</Address2>
<Address3>Wiltshire</Address3>
<Address4></Address4>
<Address5></Address5>

Address lines 1 to 3 get loaded as strings as expected but address lines 4 and 5 are NULL.
So what do I need my XML to look like for the transformation process to recognise the contents as '' and not NULL.

If it helps I do the bulk as follows:

Set objBulkLoad = CreateObject("SQLXMLBulkLoad.SQLXMLBulkLoad.3.0")
objBulkLoad.ConnectionString = gstrMmConnection
objBulkLoad.ForceTableLock = True
   
objBulkLoad.Execute gstrSchemaPath, gstrDirPath & strFileName

I have a .xsd scheme file that maps the XML tags to the relevant database columns and that looks like this:

<ElementType name="AddressLine1" dt:type="string" sql:datatype="varchar(38)"/>
<ElementType name="AddressLine2" dt:type="string" sql:datatype="varchar(38)"/>
<ElementType name="AddressLine3" dt:type="string" sql:datatype="varchar(38)"/>
<ElementType name="AddressLine4" dt:type="string" sql:datatype="varchar(38)"/>
<ElementType name="AddressLine5" dt:type="string" sql:datatype="varchar(38)"/>

<ElementType name="Member" sql:relation="Adresses" >
      <element type="AddressLine1" sql:field="MemAdd1"/>
      <element type="AddressLine2" sql:field="MemAdd2"/>
      <element type="AddressLine3" sql:field="MemAdd3"/>
      <element type="AddressLine4" sql:field="MemAdd4"/>
      <element type="AddressLine5" sql:field="MemAdd5"/>
</ElementType>

Cheers
Sam
0
Comment
Question by:Samm1502
  • 2
3 Comments
 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 500 total points
ID: 24840728
You can, in SQL, change the columns to not allow null and put a default on '' (quote quote) on them.
0
 

Author Comment

by:Samm1502
ID: 24841216
I will try that.  Thanks Sam
0
 

Author Closing Comment

by:Samm1502
ID: 31603218
The only reason I didn't give this an A is that I couldn't in fact disallow NULLS and add a default to the column without getting a crash saying column x does not allow NULL values.  What I had to do was allow NULLS then also place a default('') on the column and it works great now.

Many thanks
Sam
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now