簡體   English   中英

如何使用 SQL 中的附加組合值從一個表插入到另一個表中?

[英]How to insert from one table into another with additional combination values in SQL?

我有兩個表,我想從表 1 插入到表 2,架構將像

表格1

[Id]      UNIQUEIDENTIFIER NOT NULL,
[Name]    VARCHAR(140) NULL,
[Address] VARCHAR(140) NULL,

表 2

[Id]          UNIQUEIDENTIFIER NOT NULL,
[Name]        VARCHAR(140) NULL,
[Address]     VARCHAR(140) NULL, 
[Description] VARCHAR(140) NULL,

這是我嘗試過的:

INSERT INTO Table_2 (Id, Name, Address, Description) 
    SELECT * FROM Table_1

但我希望Table_2 DescriptionNameAddress組合。 例如,如果我有

Id    Name    Address
---------------------
1     John    NewYork

table_1 ,我想要

Id    Name     Address     Description
---------------------------------------
1     John     NewYork     John_NewYork

table_2

無論如何我可以做到這一點嗎? 謝謝

是的,我認為你可以這樣做

INSERT INTO Table_2 (Id, Name, Address, Description) 
SELECT Id, Name, Address, Name+'_'+Address FROM Table_1

試試那個。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM