简体   繁体   English

无法绑定多部分标识符

[英]The multi-part identifier could not be bound

Why do I get this error: 为什么我会收到此错误:

The multi-part identifier could not be bound on line 18 多部分标识符不能绑定在第18行
The multi-part identifier "ShipTB.sh_Type" could not be bound. 无法绑定多部分标识符“ShipTB.sh_Type”。
Line 32 the multi-part identifier "ShipTB.sh_Type" could not be bound. 第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                                     

You can't do this, this way. 你不能这样做。 The ShipTB.sh_Type in the IF statement is a result set, it is a field that contains multiple values. IF语句中的ShipTB.sh_Type是一个结果集,它是一个包含多个值的字段。 Furthermore, it cannot be refer to outside the SELECT clause. 此外,它不能引用SELECT子句外部。 If this field ShipTB.sh_Type supposed to contains only one value, then you can select it into a scalar variable like @type then put it in the condition. 如果此字段ShipTB.sh_Type应该只包含一个值,那么您可以将其选择为像@type这样的标量变量,然后将其置于条件中。

Otherwise, if this field ShipTB.sh_Type contains more values, then I think you are trying to do a conditional join, in this case you can do that in one query, like so: 否则,如果此字段ShipTB.sh_Type包含更多值,那么我认为您正在尝试进行条件连接,在这种情况下,您可以在一个查询中执行此操作,如下所示:

...

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)) + '%';

...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM