0

我使用此存储过程来显示文档处于待处理状态

create procedure b
as
  select         
     dbo.DocumentInfo.DocID, dbo.DocumentInfo.DocName, 
     dbo.DocumentInfo.Uploadfile, dbo.DocType.Doc      Type,
     dbo.Department.DepType, ApproveType.ApproveType
 from 
     dbo.DocumentInfo 
 left join 
     dbo.DocType on dbo.DocumentInfo.DocTypeID = dbo.DocType.DocTypeID 
 left join 
     dbo.Department on dbo.DocumentInfo.DepID = dbo.Department.DepID 
 inner join      
     ApproveType on DocumentInfo.ApproveID = ApproveType.ApproveID 
                 and (ApproveType.ApproveID = 3)

但是当我检查此查询时,它无法向我显示任何文件..

问题出在哪里?

4

1 回答 1

0

您的问题是您在连接不包括数据的表上直接连接(INNER JOIN)。因此,要么 table 中的列ApproveIDDocumentInfo包含数据,要么 table 中没有与ApproveTypecolumn匹配的行ApproveID

在我看来,如果您打算以这种方式使用此存储过程,那么无论如何您都在错误地使用连接 - 您绝对可以考虑使用表别名,如下所示:

CREATE PROCEDURE b
AS
    SELECT  di.DocID, 
            di.DocName, 
            di.Uploadfile, 
            dt.DocType,
            d.DepType, 
            at.ApproveType
    FROM    DocumentInfo di
        LEFT OUTER JOIN
            DocType dt ON dt.DocTypeID = di.DocTypeID
        LEFT OUTER JOIN 
            Department d ON d.DepID = di.DepID
        LEFT OUTER JOIN
            ApproveType at ON at.ApproveID = di.ApproveID 
   AND  at.ApproveID = 3
于 2013-10-16T12:44:35.750 回答