节目经理批准文件tHRough商店程序

时间:2013-12-25 14:23:06

标签: mysql asp.net sql sql-server sql-server-2008

我有一个场景,当任何用户首次上传文件时,首先要向主管批准然后当主管批准/拒绝文件然后只批准文件然后再次经理然后经理批准/拒绝文件然后只批准文件显示到最终批准的主任

ALTER PROCEDURE [dbo].[ALLDOCUMNETS]
AS
 begin
SELECT DocumentInfo.DocID as DocumentID, 
dbo.DocumentInfo.DocName as DocumentName,
dbo.DocumentInfo.Uploadfile as FileUploaded, 
dbo.DocumentInfo.UploadedBy as UploadedBy,
dbo.Userss.Email as UserEmail,
dbo.DocType.DocType as Document, 
dbo.Department.DepType as Department ,
dbo.Approval.AppoveBy, 

dbo.ApproveType.ApproveType as Status

FROM dbo.Department
left JOIN dbo.DocumentInfo
ON dbo.DocumentInfo.DepID=dbo.Department.DepID 

left JOIN dbo.DocType
     ON  dbo.DocumentInfo.DocTypeID=dbo.DocType.DocTypeID
 inner JOIN dbo.Userss on Userss.UserName =dbo.DocumentInfo.UploadedBy 

  inner join  dbo.Approval ON dbo.DocumentInfo.DocID = dbo.Approval.DocID INNER JOIN
    dbo.ApproveType ON dbo.Approval.ApproveID = dbo.ApproveType.ApproveID 
  AND  dbo.ApproveType.ApproveType = 'Approve'  
  left join Designation on dbo.Userss.DesigID=dbo.Designation.DesigID

 WHERE designation.DesigType = 'Manager'

看到这张图片 record in table

在上面的图片记录中,kanez是经理,而sundus是主管

在这里我想只显示kanez批准文件显示给导演然后他将能够最终批准但是这里主管和经理文件都去导演但我想只显示kanez文件批准文件给导演??

TABLES tables 表格视图

我是怎么做到的?

指定表 这是我的指定表

 DesignID DesigType
 1        SuperVisor
 2        Manager
 3        Director
  4       BasicUsers

这是我的批准表

SeqNo DocID ApproveID AppoveBy    ApproveDate
 258   30     1          sundus 2013-12-25 18:33:36.373
 259    30    1          kaneez 2013-12-25 18:34:47.347

现在请告诉我我能做什么

2 个答案:

答案 0 :(得分:0)

添加到您的查询:

inner JOIN dbo.Userss on Userss.UserName =dbo.DocumentInfo.UploadedBy
                       AND UserTypeId = manger

答案 1 :(得分:0)

现在再次,因为我不知道你所有表格的确切模式,我只猜测你的Users table有一个DesignID的字段,我创建了一个变量@ApprovedBy in您的程序,现在如果您想从某一级别的人那里获得所有已批准的文件,您需要将Designation作为参数传递给您的程序,它将提取该级别批准的所有文件员工。

同时检查用户表的拼写,因为您使用了双重用户,不确定是否确实如此,或者拼写错误。

ALTER PROCEDURE [dbo].[ALLDOCUMNETS]
@ApprovedBy VARCHAR(50)
AS
 BEGIN
  SET NOCOUNT ON;

    SELECT 
            DocumentInfo.DocID as DocumentID, 
            dbo.DocumentInfo.DocName as DocumentName,
            dbo.DocumentInfo.Uploadfile as FileUploaded, 
            dbo.DocumentInfo.UploadedBy as UploadedBy,
            dbo.Userss.Email as UserEmail,
            dbo.DocType.DocType as Document, 
            dbo.Department.DepType as Department ,
            dbo.Approval.AppoveBy, 
            dbo.ApproveType.ApproveType as Status

    FROM dbo.Department INNER JOIN dbo.DocumentInfo
    ON dbo.DocumentInfo.DepID = dbo.Department.DepID 
    INNER JOIN dbo.DocType
    ON dbo.DocumentInfo.DocTypeID = dbo.DocType.DocTypeID
    INNER JOIN dbo.Userss 
    ON Userss.UserName =dbo.DocumentInfo.UploadedBy 
    INNER JOIN  dbo.Approval 
    ON dbo.DocumentInfo.DocID = dbo.Approval.DocID 
    INNER JOIN dbo.ApproveType 
    ON dbo.Approval.ApproveID = dbo.ApproveType.ApproveID 
    LEFT JOIN Designation 
    ON dbo.Userss.DesigID=dbo.Designation.DesigID
    WHERE designation.DesigType = 'Manager'
    AND  dbo.ApproveType.ApproveType = 'Approve'  
    AND dbo.Approval.AppoveBy IN (SELECT UserName 
                                  FROM Userss.UserName INNER JOIN designation 
                                  ON Userss.DesignID = designation.DesignID
                                  WHERE designation.DesigType = @ApprovedBy)
END

调用Proc

获得经理批准的所有文件,只需执行类似......

的操作
  EXECUTE dbo.ALLDOCUMNETS @ApprovedBy = 'Manager'

获得主管批准的所有文件,只需执行......

  EXECUTE dbo.ALLDOCUMNETS @ApprovedBy = 'Supervisor'

依旧.....