I was unable to re-produce the issue you are having.
I created a simple schema with on element which is a nillable date.
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://Scratch2.Schema.SO72560754" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://Scratch2.Schema.SO72560754" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Root">
<xs:complexType>
<xs:sequence>
<xs:element name="NillableDate" nillable="true" type="xs:date" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
I made a second schema the same except I named the filed simply date.
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://Scratch2.Schema.SO72560754_out" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://Scratch2.Schema.SO72560754_out" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Root">
<xs:complexType>
<xs:sequence>
<xs:element name="Date" nillable="true" type="xs:date" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
And mapped the two together and deployed it to BizTalk.
I passed the following message through BizTalk with a XMLReceive Pipeline and the map on the Inbound Maps on the Receive Port.
<ns1:Root xmlns:ns1="http://Scratch2.Schema.SO72560754" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<NillableDate xsi:nil="true" />
</ns1:Root>
And got the expected output with the date field still there and being Nill.
<ns0:Root xmlns:ns0="http://Scratch2.Schema.SO72560754_out" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Date xsi:nil="true" />
</ns0:Root>
Note
- that there is a difference between empty field (either
<Date/>
or <Date></Date>
) and a field that is Nill (<Date xsi:nil="true" />
). If you are doing XML validation the empty dates would fail.
- MinOccurs = 1 is the default value if nothing is specified.
- If both source and destination elements are mandatory (e.g. must be there), then you don't need to do anything fancy, just map them as you would any other fields and no functoids necessary. It is only if the source is optional and the destination is mandatory that you have to do some fancy workarounds.
SQL
Yes, with the SQL Bindings, if the field is NULL then it will omit the field. A quick and dirty fix would be just to add some concatenate functoids in the map as below and have it concatenate to an empty string. This will produce a XML payload like below. Note: This would fail if you tried to validate it against the schema as an empty string is not a valid date, and also any numeric fields would also fail, but by default, BizTalk does not validate unless you tell it to.

<ns0:Root xmlns:ns0="http://Scratch2.Schema.SO72560754">
<account_id>267336302 </account_id>
<hus_id/>
<date_left/>
</ns0:Root>
If you want to get XML that validates then you can follow Sandro's example, but all you have to do is rather than is the IsNill functoid, is to use the Logical Date Functoid and adjust the logic accordingly (as it inverts the true/false).

That will produce
<ns0:Root xmlns:ns0="http://Scratch2.Schema.SO72560754" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<account_id>267336302</account_id>
<hus_id />
<date_left xsi:nil="true" />
</ns0:Root>
You could also use the Logical String and Logical Number functoids if you have fields of that type that you also want to have nillable="true"
on.