Solved

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

Posted on 2009-07-13
3
356 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

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…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

634 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