我尝试使用此存储过程来显示文档:
ALTER procedure [dbo].[financespmanager]
@DepID int
as
SELECT
dbo.DocumentInfo.DocID as DocumentID,
dbo.DocumentInfo.DocName as DocumentName,
dbo.DocumentInfo.Uploadfile as FileUploaded,
dbo.Department.DepType as Department,
dbo.DocType.DocType as Document,
dbo.DocumentInfo.UploadedBy as UploadedBy,
dbo.Approval.AppoveBy,
dbo.ApproveType.ApproveType as Status
FROM
dbo.DocumentInfo
INNER JOIN
dbo.Approval ON dbo.DocumentInfo.DocID = dbo.Approval.DocID
INNER JOIN
dbo.ApproveType ON dbo.Approval.ApproveID = dbo.ApproveType.ApproveID
INNER JOIN
dbo.Department ON dbo.DocumentInfo.DepID = dbo.Department.DepID
INNER JOIN
dbo.DocType ON dbo.DocumentInfo.DocTypeID = dbo.DocType.DocTypeID
WHERE
DocumentInfo.DepID = @DepID
现在,当我测试查询时,它会像我一样显示
DocumentID DocumentName FileUploaded Departmen UploadedBy AppoveBy Status
25 css dsfsdf.docx Computer edward halten Rejected
18 hr HR.docx Computer john halten Approved
19 eco eco 2.docx Computer kety halten Rejected
24 plan December8.pdf Computer edward halten Approved
现在,我想在此处仅显示已批准的文件,而不是拒绝和待处理的文件
我该怎么做?
答案 0 :(得分:2)
您的WHERE
子句中只需要一个附加条件:
WHERE
DocumentInfo.DepID = @DepID
AND dbo.ApproveType.ApproveType = 'Approved'
应该这样做。
答案 1 :(得分:1)
尝试...
AND ApproveType.ApproveType = 'Approved'
在where
子句中。
或者,更改存储过程以获取第二个参数 ...
ALTER procedure [dbo].[financespmanager]
@DepID int,
@Status varchar(30) = 'Approved'
as
--rest of sp
WHERE
DocumentInfo.DepID = @DepID
AND ApproveType.ApproveType = @Status
默认值为Approved
,但您也可以传入另一个值来覆盖...
EXEC [dbo].[financespmanager] @DepID = n, @Status = 'Rejected'
这将允许您“按原样”使用SP,但也可以灵活地覆盖。