Question : subquery returned more than 1 value: database vendor code 512

We have the sql view below that is returning error above.  I've read references to repeating alias names for same tables and other citations for solutions.  Can an expert help us troubleshoot?  Thanks...

 
SELECT     p.dob, pctc.patient_id, pctc.patient_assignment_id, dwect.doc_session_no AS dw_session#, de.doc_code, pctc.clinical_transaction_no,
                      LTRIM(RTRIM(p.lname)) + ', ' + LTRIM(RTRIM(p.fname)) + ' - ' + p.patient_id AS Patient, dwect.total_treatments, pctc.axis_I_II_1 AS CT_dx,
                      dwect.patient_dx AS DW_Dx,
                          (SELECT     TOP (1) axis_I_II_1
                            FROM          dbo.Patient_Clin_Tran_Cov AS pctc3 WITH (nolock)
                            WHERE      (axis_I_II_1 IS NOT NULL) AND (protocol_id = '7934')) AS DX, de.created_date, dwect.modality, pctc.coverage_plan_id, pctc.proc_code,
                      pctc.proc_chron,
                          (SELECT     TOP (1) proc_chron
                            FROM          dbo.Patient_Clin_Tran_Cov AS pctc1 WITH (nolock)
                            WHERE      (patient_id = pctc.patient_id) AND (episode_id = pctc.episode_id) AND (proc_chron < pctc.proc_chron) AND (proc_code LIKE 'ECT%') AND
                                                   (payor_payment > 0.00)
                            ORDER BY proc_chron DESC) AS Prev_tx,
                          (SELECT     TOP (1) proc_chron
                            FROM          dbo.Patient_Clin_Tran_Cov AS pctc WITH (nolock)
                            WHERE      (p.patient_id = patient_id) AND (p.episode_id = episode_id) AND (protocol_id = '7934') AND (proc_code = 'MDEVLPSYDX') AND
                                                   (payor_payment > 0.00)) AS Consult_Date,
                          (SELECT     TOP (1) proc_code
                            FROM          dbo.Patient_Clin_Tran_Cov AS pctc WITH (nolock)
                            WHERE      (p.patient_id = patient_id) AND (p.episode_id = episode_id) AND (protocol_id = '7934') AND (proc_code = 'MDEVLPSYDX') AND
                                                   (payor_payment > 0.00)) AS Consult_Code,
                          (SELECT     TOP (1) billing_id
                            FROM          dbo.Patient_Clin_Tran_Cov AS pctc WITH (nolock)
                            WHERE      (p.patient_id = patient_id) AND (p.episode_id = episode_id) AND (protocol_id = '7934') AND (proc_code = 'MDEVLPSYDX') AND
                                                   (payor_payment > 0.00)) AS Consult_Id,
                          (SELECT     LTRIM(RTRIM(s1.fname)) + ' ' + LTRIM(RTRIM(s1.lname)) + ', M.D.' AS Expr1
                            FROM          dbo.Patient_Clin_Tran_Cov AS pctc1 WITH (nolock) INNER JOIN
                                                   dbo.Staff AS s1 ON pctc1.billing_id = s1.staff_id
                            WHERE      (p.patient_id = pctc1.patient_id) AND (p.episode_id = pctc1.episode_id) AND (pctc1.protocol_id = '7934') AND
                                                   (pctc1.proc_code = 'MDEVLPSYDX') AND (s1.status = 'A') AND (pctc1.payor_payment > 0.00)) AS Consult_Name
FROM         dbo.Patient_Clin_Tran_Cov AS pctc WITH (nolock) LEFT OUTER JOIN
                      dbo.Doc_Entity AS de WITH (nolock) ON pctc.clinical_transaction_no = de.clinical_transaction_no LEFT OUTER JOIN
                      dbo.doc_dw_wpic_ect AS dwect WITH (nolock) ON de.doc_session_no = dwect.doc_session_no AND
                      de.current_version_no = dwect.version_no INNER JOIN
                      dbo.Patient AS p WITH (nolock) ON pctc.patient_id = p.patient_id AND pctc.episode_id = p.episode_id INNER JOIN
                      dbo.Staff AS s WITH (nolock) ON pctc.billing_id = s.staff_id
WHERE     pctc.patient_id = '00331154' and (de.doc_code IS NULL OR
                      de.doc_code = 'ECT') AND (pctc.payor_payment > 0.00) AND (pctc.proc_chron <= GETDATE()) AND (p.lname <> 'test')

Answer : subquery returned more than 1 value: database vendor code 512

Subselect in the SELECT clause must return only one row and only one column. The problem is at the last subselect which does not begin TOP(1). So you should check the following subselect or simply complete it with a TOP(1)

1:
2:
3:
4:
5:
(SELECT     LTRIM(RTRIM(s1.fname)) + ' ' + LTRIM(RTRIM(s1.lname)) + ', M.D.' AS Expr1
                            FROM          dbo.Patient_Clin_Tran_Cov AS pctc1 WITH (nolock) INNER JOIN
                                                   dbo.Staff AS s1 ON pctc1.billing_id = s1.staff_id
                            WHERE      (p.patient_id = pctc1.patient_id) AND (p.episode_id = pctc1.episode_id) AND (pctc1.protocol_id = '7934') AND 
                                                   (pctc1.proc_code = 'MDEVLPSYDX') AND (s1.status = 'A') AND (pctc1.payor_payment > 0.00)) AS Consult_Name
Random Solutions  
 
programming4us programming4us