SSIS MySQL and a Date column

Hello Experts Exchange
I am writing a SSIS package that transfers data from MySQL into Microsoft SQL Server, I have a problem with a date field.

This is my MySQL Query to get the data;
SELECT o.order_date as Date,  
'' as 'Open Acc PO No',
concat(cast(o.locid as char),'-', date_format(order_date,'%m%d'),'-',cast(o.ordid as char)) as 'Cybertill PO No', 
'' as 'Retail Stores Dispatch Date',
s.sup_name as Supplier, 
i.itemref as 'Product Code',
Replace(Replace(Replace(i.item_name, "&", "&"), """, """"), "£", "£") as Description,
Replace(Replace(Replace(ifnull(cat2.catName,''), "&", "&"), """, """"), "£", "£") as 'Category 2',
Replace(Replace(Replace(ifnull(cat3.catName,''), "&", "&"), """, """"), "£", "£") as 'Category 3',
Replace(Replace(Replace(ifnull(cat4.catName,''), "&", "&"), """, """"), "£", "£") as 'Category 4',
pi.qty_ordered as 'Qty Ordered',
pi.qty_delivered as 'Qty Delivered',
pi.qty_ordered - pi.qty_delivered as 'Qty Outstanding',
o.dateby as 'Due Date',     
date(o.del_date) as 'Delivery Date'
FROM `pdsa_classic`.`pop_order` as o inner join `pdsa_classic`.`sup_main` as s on s.supid = o.supid 
inner join `pdsa_classic`.`pop_items` as pi on pi.ordid = o.ordid inner join `pdsa_classic`.`stk_item` as i 
on i.itemid = pi.itemid inner join stk_products as p on p.prodID = i.prodID 
left outer join stk_cat as cat1 on cat1.catID = cast((mid(category,length(substring_index(category,'.',1))+2,length(substring_index(category,'.',2))-length(substring_index(category,'.',1))-1)) as decimal) 
left outer join stk_cat as cat2 on cat2.catID = cast((mid(category,length(substring_index(category,'.',2))+2,length(substring_index(category,'.',3))-length(substring_index(category,'.',2))-1)) as decimal) 
left outer join stk_cat as cat3 on cat3.catID = cast((mid(category,length(substring_index(category,'.',3))+2,length(substring_index(category,'.',4))-length(substring_index(category,'.',3))-1)) as decimal) 
left outer join stk_cat as cat4 on cat4.catID = cast((mid(category,length(substring_index(category,'.',4))+2,length(substring_index(category,'.',5))-length(substring_index(category,'.',4))-1)) as decimal) 
inner join data_vat as v on v.ID = p.vatID 
where date(o.order_date) >= '"+str(lnYear)+"-01-01' 
and o.status <> 'void' 
and o.status <> 'pending'
and o.status <> 'complete'
and pi.qty_ordered-pi.qty_delivered >0 
order by o.order_date, o.ordid, i.itemref

Open in new window

When I preview the data the date field called 'Delivery Date' has data in some fields and some fields that say "<Error displaying this cell>".

When I remove the 'Delivery Date' from the SQL script the package works fine.

Is there a way I can change my SQL Script to set  "<Error displaying this cell>" to a default date?  Or is there another process I can add to the SSIS package to set a default date for the error fields?


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
what's the date format for o.del_date? is it a char field?

you can try either...

IF ( STR_TO_DATE(o.del_date, '%d/%m/%Y') IS  NULL  , NULL  ,  date(o.del_date) ) as 'Delivery Date'

Open in new window

replace the second "NULL" to a default date you want when necessary

STR_TO_DATE(o.del_date, '%d/%m/%Y') as 'Delivery Date'

Open in new window

replace the %d/%m/%Y with the actual format accordingly.
SQLSearcherAuthor Commented:
Hello Ryan Chong
None of your suggestions have worked the o.del_date is a date field, but has the following data when a delivery has not been made.

01/01/0001 00:00:00


Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
ok, try this...
IF(DATE_FORMAT(date(o.del_date),'%d/%m/%Y')='01/01/2001', date(Now()), o.del_date) as 'Delivery Date'

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SQLSearcherAuthor Commented:
Thank you for your help, the SQL I end up with is;

IF(o.del_date,date_format(o.del_date, '%d/%m/%Y'),NULL) as 'Delivery Date'


It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.