2012-03-19 70 views
-1

我有2個表 faxhistory和臨時MySQL查詢,多個插入件,交叉表更新

faxhistory是空 臨時填充

溫度每一列類型是VARCHAR

我需要作出1查詢插入從臨時 的每一行,但在此之前,將數據(varchar轉換爲int等)

+0

什麼樣的colums在那裏? – hjpotter92 2012-03-19 09:52:34

+0

http://mattgemmell.com/2008/12/08/what-have-you-tried/ – 2012-03-19 09:53:42

+0

faxhistory - 身份證傳真日期時間status_code status_text持續時間頁碼循環company_id 臨時 - faxnumber日期時間status_code status_text持續時間頁面 – cakecoke 2012-03-19 09:54:53

回答

0

您可以使用cast('column' as decimal(p,s))將您的var char字段編號。

嘗試以下操作:

select cast(t.'column1' as decimal(p,s)), cast(t.'column2' as decimal(p,s)), t.'columnN' 
into f.'column1', f.'column2', f.'columnN' 
from faxhistory f, temp t 
0

在這裏,有一個cookie:

CREATE TABLE `faxhistory` ( <your create statement>) COLLATE 'utf8_general_ci'; 
INSERT INTO `faxhistory` (`id`, `fax`, `date`, `time`, `status_code`, `status_text`, `duration`, `pages`, `loops`, `company_id`) SELECT `id`, `fax`, `date`, `time`, `status_code`, `status_text`, `duration`, `pages`, `loops`, `company_id` FROM `temp`; 

上面的代碼只有當你的faxhistory仍然是空的!否則,在任何列和任何集合上使用以下內容。

ALTER TABLE `faxhistory` CHANGE COLUMN `id` `id` INT NOT NULL;