子查询返回超过 1 value.how 来处理这个并获得多个 id
Subquery returned more than 1 value.how to handle this and get multiple ids
SET @IdInternalSelection = (
SELECT iss.IdInternalSelection
FROM HesSelection.InternalSelection iss
INNER JOIN HesSelection.ExtractedLabInternalSelection2CatPatientActivity cpa
ON iss.IdInternalSelection = cpa.IdInternalSelection
WHERE cpa.IdCatPatientActivity = @IdCatPatientActivity)
我将从另一个查询中获得 IdCatPatientActivity
的输出。
基于此 IdCatPatientActivity
,我需要设置 IdInternalSelection
,但某些 IdCatPatientActivity
id 会失败。
这是因为 IdCatPatientActivity 在某些情况下与多个 IdInternalSelection 相关联
我需要的是获取与 IdCatPatientActivity 关联的所有 IdInternalSelection,然后循环每个 IdInternalSelection 并将其插入不同的 table。
我没有获得多个 IdInternalSelection ID。
有人可以帮帮我吗?
您需要变量的类型为TABLE。
declare @IdInternalSelection table
(
Id varchar(1000)
)
insert into @IdInternalSelection
SELECT iss.IdInternalSelection
FROM HesSelection.InternalSelection iss
INNER JOIN HesSelection.ExtractedLabInternalSelection2CatPatientActivity cpa ON iss.IdInternalSelection = cpa.IdInternalSelection
WHERE cpa.IdCatPatientActivity = @IdCatPatientActivity
SET @IdInternalSelection = (
SELECT iss.IdInternalSelection
FROM HesSelection.InternalSelection iss
INNER JOIN HesSelection.ExtractedLabInternalSelection2CatPatientActivity cpa
ON iss.IdInternalSelection = cpa.IdInternalSelection
WHERE cpa.IdCatPatientActivity = @IdCatPatientActivity)
我将从另一个查询中获得 IdCatPatientActivity
的输出。
基于此 IdCatPatientActivity
,我需要设置 IdInternalSelection
,但某些 IdCatPatientActivity
id 会失败。
这是因为 IdCatPatientActivity 在某些情况下与多个 IdInternalSelection 相关联
我需要的是获取与 IdCatPatientActivity 关联的所有 IdInternalSelection,然后循环每个 IdInternalSelection 并将其插入不同的 table。
我没有获得多个 IdInternalSelection ID。 有人可以帮帮我吗?
您需要变量的类型为TABLE。
declare @IdInternalSelection table
(
Id varchar(1000)
)
insert into @IdInternalSelection
SELECT iss.IdInternalSelection
FROM HesSelection.InternalSelection iss
INNER JOIN HesSelection.ExtractedLabInternalSelection2CatPatientActivity cpa ON iss.IdInternalSelection = cpa.IdInternalSelection
WHERE cpa.IdCatPatientActivity = @IdCatPatientActivity