【发布时间】:2011-10-24 21:21:40
【问题描述】:
我必须编写一个存储过程来填充收入。要求是我有两个部分,患者和配偶/其他,其中患者收入必须填写在他的部分下,而配偶/其他部分应该在该部分下。
当配偶/其他部分的成员超过一个时,我遇到了问题!下面是我的代码。
错误信息表明----
"@OtherMSN" "子查询返回超过 1 个值。这不是 当子查询跟随 =、!=、、>= 或当 子查询用作表达式。”
非常感谢任何帮助。
declare @app_id varchar(20), @msn int
declare @patient_msn varchar(5)
set @patient_msn = (select msn from EXT_KSR_APP_MEMBERS (nolock) where app_id=@app_id and msn =@msn)
declare @OtherMSN varchar(3)
set @OtherMSN = (SELECT MSN FROM EXT_KSR_APP_MEMBERS (nolock) WHERE APP_ID = @app_id and msn <> @msn)
select distinct
(select gross_amount from app_income (nolock) where app_id = @app_id and income_type = 'EJ' and msn = @patient_msn) as gross_salary_patient,
(select gross_amount from app_income (nolock) where app_id = @app_id and income_type = 'CA' and msn = @patient_msn) as cash_income_patient,
(select sum(gross_amount) from app_income (nolock) where app_id = @app_id and income_type in('ER','RT','S','SR') and msn = @patient_msn) as gross_ssn_income_patient,
(select gross_amount from app_income (nolock) where app_id = @app_id and income_type ='L' and msn = @patient_msn) as unemp_ben_patient,
(select gross_amount from app_income (nolock) where app_id = @app_id and income_type ='J' and msn = @patient_msn) as st_disability_inc_patient,
(select gross_amount from app_income (nolock) where app_id = @app_id and income_type ='A' and msn = @patient_msn)as a_c_support_patient,
(select gross_amount from app_income (nolock) where app_id = @app_id and income_type ='M' and msn = @patient_msn) as pen_inc_patient,
(select gross_amount from app_income (nolock) where app_id = @app_id and income_type ='RI' and msn = @patient_msn) as ren_prp_inc_patient,
--(select sum(gross_amount) from app_income (nolock) where app_id = @app_id and income_type in('19','8','CR','FI','FS','G1','GA','IA','IC','IE','II','IK','IP','IU','LO','N','O','P','R','RI','T','TAN','TR') and msn = 1) as other_source_patient,
(select sum(gross_amount) from app_income (nolock) where app_id = @app_id and income_type in('ER','RT','S','SR','EJ','CA','L','J','A','M','RI','19','8','CR','FI','FS','G1','GA','IA','IC','IE','II','IK','IP','IU','LO','N','O','P','R','RI','T','TAN','TR') and msn = @patient_msn) as total_mon_inc_patient
from app_member mem (nolock)
inner join app_income inc (nolock)
on mem.app_id = inc.app_id and mem.msn = inc.msn
where mem.app_id = @app_id and mem.msn = @patient_msn
select distinct
(select sum(gross_amount) from app_income (nolock) where app_id = @app_id and income_type = 'EJ' and msn in (@OtherMSN)) as gross_salary_oth,
(select sum(gross_amount) from app_income (nolock) where app_id = @app_id and income_type = 'CA' and msn in (@OtherMSN)) as cash_income_oth,
(select sum(gross_amount) from app_income (nolock) where app_id = @app_id and income_type in('ER','RT','S','SR') and msn in (@OtherMSN)) as gross_ssn_income_oth,
(select sum(gross_amount) from app_income (nolock) where app_id = @app_id and income_type ='L' and msn in (@OtherMSN)) as unemp_ben_oth,
(select sum(gross_amount) from app_income (nolock) where app_id = @app_id and income_type ='J' and msn in (@OtherMSN)) as st_disability_inc_oth,
(select sum(gross_amount) from app_income (nolock) where app_id = @app_id and income_type ='A' and msn in(@OtherMSN))as a_c_support_oth,
(select sum(gross_amount) from app_income (nolock) where app_id = @app_id and income_type ='M' and msn in (@OtherMSN)) as pen_inc_oth,
(select sum(gross_amount) from app_income (nolock) where app_id = @app_id and income_type ='RI' and msn in (@OtherMSN)) as ren_prp_inc_oth,
-- (select sum(gross_amount) from app_income(nolock) where app_id = @app_id and income_type in ('19','8','CR','FI','FS','G1','GA','IA','IC','IE','II','IK','IP','IU','LO','N','O','P','R','RI','T','TAN','TR') and msn = @OtherMSN) as other_source_oth,
(select sum(gross_amount) from app_income (nolock) where app_id = @app_id and income_type in('ER','RT','S','SR','EJ','CA','L','J','A','M','RI','19','8','CR','FI','FS','G1','GA','IA','IC','IE','II','IK','IP','IU','LO','N','O','P','R','RI','T','TAN','TR') and msn in (@OtherMSN)) as total_mon_inc_oth
from app_member mem (nolock)
inner join app_income inc (nolock)
on mem.app_id = inc.app_id and mem.msn = inc.msn
where mem.app_id = @app_id and mem.msn in (@OtherMSN)
【问题讨论】:
-
您在哪些方面需要帮助?错误的原因很简单,错误中解释了。
标签: sql-server stored-procedures