Jes Sie

Jes Sie

  • 704
  • 1.2k
  • 265.1k

Subquery returned more than 1 value

Jul 29 2020 2:41 AM
Can someone help me solve the error of my query?
  1. UPDATE [dbo].[fin_PaymentSchedule_Master]  
  2.                        SET  
  3.                              ActualPaymentDate_ColS = GETDATE()  
  4.                             ,[PaymentVoucher_ColT] = 'PV-200780'  
  5.                             ,pyLAK_ColU =  
  6.                                 (  
  7.                                     CASE  
  8.                                         WHEN  
  9.                                             (SELECT TOP(1) CurrencyPayment FROM fin_PaymentVoucher_Header WHERE PV_No = 'PV-200780' ORDER BY Id DESC) = 'LAK'  
  10.                                         THEN  
  11.                                             (SELECT SUM(AmountPaid + Vat) FROM fin_PaymentVoucher_Details WHERE AP_Number = 'AP19-3131')  
  12.   
  13.                                         WHEN  
  14.                                             (SELECT TOP(1) CurrencyPayment FROM fin_PaymentVoucher_Header WHERE PV_No = 'PV-200780' ORDER BY Id DESC) = 'THB'  
  15.                                         THEN 0  
  16.   
  17.                                         WHEN  
  18.                                             (SELECT TOP(1) CurrencyPayment FROM fin_PaymentVoucher_Header WHERE PV_No = 'PV-200780' ORDER BY Id DESC) = 'USD'  
  19.                                         THEN 0  
  20.                                     END  
  21.                                 )  
  22.                             ,pyTHB_ColV =  
  23.                                 (  
  24.                                     CASE  
  25.                                         WHEN  
  26.                                             (SELECT TOP(1) CurrencyPayment FROM fin_PaymentVoucher_Header WHERE PV_No = 'PV-200780' ORDER BY Id DESC) = 'THB'  
  27.                                         THEN  
  28.                                             (SELECT SUM(CurAmtPaid) FROM fin_PaymentVoucher_Details WHERE AP_Number = 'AP19-3131')  
  29.   
  30.                                         WHEN  
  31.                                             (SELECT TOP(1) CurrencyPayment FROM fin_PaymentVoucher_Header WHERE PV_No = 'PV-200780' ORDER BY Id DESC) = 'LAK'  
  32.                                         THEN 0  
  33.   
  34.                                         WHEN  
  35.                                             (SELECT TOP(1) CurrencyPayment FROM fin_PaymentVoucher_Header WHERE PV_No = 'PV-200780' ORDER BY Id DESC) = 'USD'  
  36.                                         THEN 0  
  37.                                     END  
  38.                                 )  
  39.   
  40.                                 ,pyUSD_ColW =  
  41.                                 (  
  42.                                     CASE  
  43.                                         WHEN  
  44.                                             (SELECT TOP(1) CurrencyPayment FROM fin_PaymentVoucher_Header WHERE PV_No = 'PV-200780' ORDER BY Id DESC) = 'USD'  
  45.                                         THEN  
  46.                                             (SELECT SUM(CurAmtPaid) FROM fin_PaymentVoucher_Details WHERE AP_Number = 'AP19-3131')  
  47.   
  48.                                         WHEN  
  49.                                             (SELECT TOP(1) CurrencyPayment FROM fin_PaymentVoucher_Header WHERE PV_No = 'PV-200780' ORDER BY Id DESC) = 'LAK'  
  50.                                         THEN 0  
  51.   
  52.                                         WHEN  
  53.                                             (SELECT TOP(1) CurrencyPayment FROM fin_PaymentVoucher_Header WHERE PV_No = 'PV-200780' ORDER BY Id DESC) = 'THB'  
  54.                                         THEN 0  
  55.                                     END  
  56.                                 )  
  57.                             ,pyTotalLAK_ColX = (SELECT SUM(AmountPaid + Vat) FROM fin_PaymentVoucher_Details WHERE AP_Number = 'AP19-3131')  
  58.                               
  59.                         WHERE AP_Number_ColA = 'AP19-3131'  
Error says:
 
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

The statement has been terminated.
 The code snipe above is only part of the sql transaction. thank you in advance.

Answers (2)