SELECT 'L' as Ind,ledger_id, Voucher_Date as Date,cast(Voucher_No as unsigned) as Voucher_No,(SELECT Ledger_Name from $master_db.Ledger_Master where Ledger_ID=stable.Ledger_ID) as Ledger,Total as 'Total Amount', Voucher_Prefix From $trans_db.Sales_Invoice_Main_Deleted stable WHERE ( str_to_Date(concat(stable.Voucher_Date,substr(`TimeStamp`,11,19)),'%Y-%m-%d %H:%i:%s')<= str_to_date('$toDateTime','%Y-%m-%d %H:%i:%s') and str_to_Date(concat(stable.Voucher_Date, substr(`TimeStamp`,11,19)) ,'%Y-%m-%d %H:%i:%s') >= str_to_date('$fromDateTime','%Y-%m-%d %H:%i:%s')) order BY cast(Voucher_No as unsigned) desc