Click here to Skip to main content
15,907,000 members
Please Sign up or sign in to vote.
1.11/5 (2 votes)
See more: , +
i have a scenario that when any user first upload document then this go for approval first to supervisor then when supervisor approve/reject documents then only approve documents go to manager then again when manager approve/reject document then only approve document shows to director for final approval

SQL
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'  

  end

http://i.stack.imgur.com/w2kS6.png[^]


here above record kanez is manager and sundus is supervisor

here i want to show only kanez approve documents show to director then he will be able to final approval but here both supervisor and manager documents go to director but i want to show only kanez document approve documents to director??

tables
http://i.stack.imgur.com/2yvGC.png[^]
Posted

Hi Ayesha,
This is quite an interesting question. I would like to say that you can achieve the result you want in 2 ways.

1st Way.
=> You didn't have any managerial column under users. It would be a good practise to have that.
Eg: you can have a manager column in Users table and assign the UserId to the column.Like. Kanez is manager of Sundus and Director guy is the manager of Kanez. So while filtering the data we can easily filter by getting all the documents that is approved by the person whoever is under this(in this case whoever works is under the Director)

2nd Way
=> Here I assume that the DesigID is the unique Id given to all managers.

Under this case.you can check
if(Director)
Begin
........ Where Users.DesigId==@ManagersDesigId
End

There would be many other possible ways to tackle this problem also. The above is just an example solution. I hope you understand the above.
 
Share this answer
 
v2
Comments
Diya Ayesa 26-Dec-13 2:10am    
ok .... i tried another way that i add column desigation id in approval table like this
SeqNo DocID ApproveID AppoveBy DesigID ApproveDate
258 30 1 sundus 1 2013-12-25 18:34:47.347
259 30 1 kaneez 2 2013-12-25 18:34:47.347



and call in sp like this..
left join dbo.Designation on dbo.Approval.DesigID=dbo.Designation.DesigID
where dbo.Designation.DesigType='Manager'

is it right or wrong?
Prasaad SJ 26-Dec-13 2:30am    
Yeah.. This should work.. Any way just have few test cases and test the results.
First of all, don't store the approve type as a string. store an id to a list of possible approval types. You can then reproduce that list as an enum in code, making it clean on both sides.

I think you're saying you want to add a where clause, where userss.username = 'kanez'. Isn't that all you need ? You're doing a lot of left joining, can I suggest you also use COALESCE for when your department is null, to return a default ? Surely if document info is null ( which is what your left join on document type caters for ), then your proc is pointless ?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900