In your union you have fields like this:
xx,yy,zz,ww,uu,...
and
xx yy zz ww d5,...
respectively.
Now:
uu
is of type datetime. But for
d5
you select '' (empty string). Because of the union the empty string is treated as zero, and as datetime respectively, thus you get the minimum value of datetime: 1900-01-01-00:00:00:00.
Is is working as expected.
You have two choices:
A) select
NULL as d5
instead of
'' as d5
, and handle null value at presentation time (will be empty string by default in most cases).
B) instead of
uu
, use
convert[
^] or cast, like this for example:
CONVERT(VARCHAR(24),uu)
, and you can keep the empty string, since both will be strings. Be aware, that in sql server below version 2012 there are only few built-in datetime formats you can choose from.