3

このエラーが発生するのはなぜですか。

18行目で
マルチパート識別子をバインドできませんでした。マルチパート識別子「ShipTB.sh_Type」をバインドできませんでした。
32行目マルチパート識別子「ShipTB.sh_Type」をバインドできませんでした。

CREATE PROCEDURE DocumentReportProc   
(
   @searchOpt tinyint,
   @keyser nvarchar (50),
   @usertypeid tinyint output
)
as
SELECT     
    ExceptionTB.excep_ref, ExceptionTB.emo_no, ShipTB.sh_Type
FROM ExceptionTB 
INNER JOIN ShipTB ON ExceptionTB.emo_no = ShipTB.Emo_No 
where ExceptionTB.excep_ref like cast(@keyser as varchar(50)) + '%'

IF  ((ShipTB.sh_Type)=('تجارية'))
BEGIN

 SELECT 
    ExceptionTB.excep_ref, 
    ExceptionTB.emo_no, 
    ExceptionTB.broker, 
    ExceptionTB.r_date, 
    ShipTB.S_Name, 
    ShipTB.sh_Type, 
    ArrivalNotiDate.Arri_noti_date, 
    ArrivalNotiDate.port, 
    CargoCertificate.[1], 
    CargoCertificate.[2], 
    CargoCertificate.[3], 
    CargoCertificate.[4], 
    CargoCertificate.[5],  
    CargoCertificate.[6], 
    CargoCertificate.[7], 
    CargoCertificate.[8]
  FROM         ExceptionTB 
  INNER JOIN  ShipTB ON ExceptionTB.emo_no = ShipTB.Emo_No 
  INNER JOIN  ArrivalNotiDate ON ExceptionTB.excep_ref = ArrivalNotiDate.exp_ref 
  INNER JOIN  CargoCertificate ON ExceptionTB.excep_ref = CargoCertificate.excep_ref    
  where ExceptionTB.excep_ref like cast(@keyser as varchar(50)) + '%'   

END      
IF  (ShipTB.sh_Type='سياحية')
BEGIN
 SELECT     
    ExceptionTB.excep_ref,
    ExceptionTB.emo_no, 
    ExceptionTB.broker, 
    ExceptionTB.r_date, 
    ShipTB.S_Name, 
    ShipTB.sh_Type, 
    ArrivalNotiDate.Arri_noti_date, 
    ArrivalNotiDate.port, 
    PassengerCertificate.[1], 
    PassengerCertificate.[2], 
    PassengerCertificate.[3], 
    PassengerCertificate.[4], 
    PassengerCertificate.[5], 
    PassengerCertificate.[6]
  FROM         dbo.ExceptionTB 
  INNER JOIN ShipTB ON ExceptionTB.emo_no = ShipTB.Emo_No  
  INNER JOIN ArrivalNotiDate ON ExceptionTB.excep_ref = ArrivalNotiDate.exp_ref  
  INNER JOIN PassengerCertificate ON ExceptionTB.excep_ref = PassengerCertificate.excep_ref  
  where ExceptionTB.excep_ref like cast(@keyser as varchar(50)) + '%'                     
END                                     
4

1 に答える 1

0

このようにこれを行うことはできません。IFステートメントのShipTB.sh_Typeinは結果セットであり、複数の値を含むフィールドです。さらに、SELECT条項の外で参照することはできません。このフィールドShipTB.sh_Typeに値が1つだけ含まれていると想定される場合は、次のようにスカラー変数に選択して@type、条件に入れることができます。

それ以外の場合、このフィールドShipTB.sh_Typeにさらに多くの値が含まれている場合は、条件付き結合を実行しようとしていると思います。この場合、次のように1つのクエリで実行できます。

...

SELECT     
  ExceptionTB.excep_ref,
  ExceptionTB.emo_no, 
  ExceptionTB.broker, 
  ExceptionTB.r_date, 
  ShipTB.S_Name, 
  ShipTB.sh_Type, 
  ArrivalNotiDate.Arri_noti_date, 
  ArrivalNotiDate.port, 
  PassengerCertificate.[1], 
  PassengerCertificate.[2], 
  PassengerCertificate.[3], 
  PassengerCertificate.[4], 
  PassengerCertificate.[5], 
  PassengerCertificate.[6]
  CargoCertificate.[1], 
  CargoCertificate.[2], 
  CargoCertificate.[3], 
  CargoCertificate.[4], 
  CargoCertificate.[5],  
  CargoCertificate.[6], 
  CargoCertificate.[7], 
  CargoCertificate.[8]
FROM       ExceptionTB 
INNER JOIN ShipTB                
        ON ExceptionTB.emo_no    = ShipTB.Emo_No 
INNER JOIN ArrivalNotiDate       
        ON ExceptionTB.excep_ref = ArrivalNotiDate.exp_ref 
INNER JOIN CargoCertificate      
        ON ExceptionTB.excep_ref = CargoCertificate.excep_ref 
       AND ShipTB.sh_Type        = 'تجارية'
INNER JOIN PassengerCertificate  
        ON ExceptionTB.excep_ref = PassengerCertificate.excep_ref  
       AND ShipTB.sh_Type        = 'سياحية'
WHERE      ExceptionTB.excep_ref LIKE CAST(@keyser as varchar(50)) + '%';

...
于 2012-12-22T16:58:00.477 に答える