Solved

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

Posted on 2009-07-13
3
352 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

685 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