[英]merging multiple Columns from table1 into one column in table2
我想將Table1中的多個現有列合並或插入到Table2中的一列中。 我在表1中有客戶的地址,但是它存儲在單個實體中(街道地址,apt,城市,州等)。 我想做的是將所有這些實體合並為一列,作為每個客戶的一個地址。 我努力了:
insert into table2(newAddress) select street_address, city, state, country from table1
但是,我出現此錯誤“列數與第1行的值數不匹配”。 謝謝你的幫助
如果您嘗試為單個字段插入值,則SQL期望您僅返回1個字段。 就您而言,您將返回4個字段: street_address, city, state, country
我不確定最終的實現方式,但是可以嘗試將4個字段合並為一個字段:
insert into table2(newAddress) select street_address + ' ' + city + ' ' + state + ' ' + country AS newAddress from table1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.