I have the following (very simplified) XML document that I read in my database using the OPENXML function:
<root>
<row>
<bar>123</bar>
</row>
<row>
<bar>0</bar>
</row>
<row>
<bar></bar>
</row>
</root>
I import into the database like this:
insert into [Foo]
([bar])
select
ds.[bar]
from openxml(@xmlHandle, 'root/row', 2)
with ([bar] int) ds
The problem is that OPENXML converts empty fields with int data type to zero, so it is inserted into my table:
bar
123
0
0
What I want to add to my table:
bar
----
123
0
NULL
How to get the OPENXML function to handle empty fields as NULL and not convert it to zero by default?
source
share