# # add perl path, rename to .pl if you please # converts stdin (insert statements from from mssql) to stdout (a format that you can import into mysql). while(<>) { if (/USE|GO|SET|print/) { next; } s/\[trueacc\].\[dbo\].\[users_info\]/users_info/; s/\[trueacc\].\[dbo\].\[users_mailbox\]/users_mailbox/; s/\[//g; s/\]//g; s/([^N'])'([^',)])/$1''$2/g; # internal quotes and end external quote s/N'/'/g; # start external quotes $dateexp = ''; $datemarker = 'x!!xxxxxxxxxxx'; while (s/CAST\(0x([0-9A-F]{8}) AS SmallDateTime\)/$datemarker/) { $hex = $1; $days_in_hex = substr($hex,0,4); $minutes_in_hex = substr($hex,4,4); $dateexp = "date_add(date_add(str_to_date('01-01-1900','%m-%d-%Y'), interval " . hex($days_in_hex)." day) , interval " . hex($minutes_in_hex)/(24*6)." minute)" ; s/$datemarker/$dateexp/g; } while (s/CAST\(0x([0-9A-F]{16}) AS DateTime\)/$datemarker/) { $hex = $1; $days_in_hex = substr($hex,0,8); $one_300s_in_hex = substr($hex,8,8); $dateexp = "date_add(date_add(str_to_date('01-01-1900','%m-%d-%Y'), interval " . hex($days_in_hex)." day) , interval " . hex($one_300s_in_hex)*300 ." second)" ; s/$datemarker/$dateexp/g; } s/$/;/; print; }