Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2009-07-13
3
Medium Priority
?
370 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 1500 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

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

773 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