You will probably want to use convert
to get the format you're after, as in:
select convert(varchar(10), MyColumn, 110) from MyTable;
Here we're converting your datetime to a character value, but with a particular date style (style 110).
Your null issue can be sorted with a case
switch or with the nullif
function:
select nullif(MyColumn, '19000101') from MyTable;
select case when MyColumn = '19000101' then null else MyColumn end from MyTable;
Note that I'm assuming MyColumn
is stored as a datetime or similar datatype. If not, then you can cast
them as such according to the above documentation.
Feel free to combine functions, as in:
select convert(varchar(10), nullif(MyColumn, '19000101'), 110) from MyTable;