SQL insert into..select + 添加多行时添加列
SQL insert into..select + add column when there are multiple rows being added
我正在尝试从我的 serviceLink
table 中向我的 TherapistRates
table 中插入多行。我需要在每一行上添加一个 therapistID
。但是,SQL 不允许我在插入多行时添加值。我该如何解决这个问题?
这是我的查询:
INSERT INTO TherapistRates (therapistID, serviceType)
VALUES (@therapistID, (SELECT (serviceID) FROM serviceLink WHERE TherapistTypeID = @therapistID)
为什么不呢:
insert into TheRapistRates (TherapistID, serviceType)
select TherapistTypeID , serviceID
from serviceLink
where TherapistTypeID = @TherapistID
新版本(来自对其他答案的评论)
insert into TheRapistRates (TherapistID, serviceType)
select @TherapistID, serviceID
from serviceLink
where TherapistTypeID = @TherapistTypeID
这是您要找的吗?
Insert TherapistRates
(therapistID, serviceType)
Select @TherapistId, ServiceId
From ServiceLink
Where TherapistTypeID = @TherapistTypeID
我正在尝试从我的 serviceLink
table 中向我的 TherapistRates
table 中插入多行。我需要在每一行上添加一个 therapistID
。但是,SQL 不允许我在插入多行时添加值。我该如何解决这个问题?
这是我的查询:
INSERT INTO TherapistRates (therapistID, serviceType)
VALUES (@therapistID, (SELECT (serviceID) FROM serviceLink WHERE TherapistTypeID = @therapistID)
为什么不呢:
insert into TheRapistRates (TherapistID, serviceType)
select TherapistTypeID , serviceID
from serviceLink
where TherapistTypeID = @TherapistID
新版本(来自对其他答案的评论)
insert into TheRapistRates (TherapistID, serviceType)
select @TherapistID, serviceID
from serviceLink
where TherapistTypeID = @TherapistTypeID
这是您要找的吗?
Insert TherapistRates
(therapistID, serviceType)
Select @TherapistId, ServiceId
From ServiceLink
Where TherapistTypeID = @TherapistTypeID