Click here to Skip to main content
15,904,348 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
i have a table which is department like

SQL
departmentid  department type
 1             computer science
 2             hr
 3               finance


here is the store procedure to view documents

SQL
ALTER PROCEDURE [dbo].[statuschange]
AS
SELECT  di.DocID, 
    di.DocName, 
    di.Uploadfile, 
    dt.DocType,
    d.DepType, 
    at.ApproveType
FROM    DocumentInfo di
JOIN
    DocType dt ON dt.DocTypeID = di.DocTypeID
JOIN 
    Department d ON d.DepID = di.DepID
LEFT OUTER JOIN
    Approval a ON a.DocID = di.DocID
JOIN
    ApproveType at ON at.ApproveID = ISNULL(a.Approveid, 3)

now i want to show documents with specific department id

computer-science admin will be able to view only computer-science documents and hr admin view only hr documents

any solution?
Posted

1 solution

You just need to pass a parameter to your stored procedure. For example:

SQL
ALTER PROCEDURE [dbo].[statuschange]
(
 @department_id INT
)
AS
SELECT  di.DocID...
WHERE department_id = @department_id


Or, if it is based on user id you can pass in the user id and then do your logic to determine what they have access to.
 
Share this answer
 
Comments
Diya Ayesa 21-Oct-13 11:09am    
when i add like this WHERE DepID = @DepID it show me error
Ambiguous column name 'DepID'.
ZurdoDev 21-Oct-13 11:11am    
That means you have the column DepID in more than one table and it does not know which one you are talking about.

Do either d.DepID or di.DepID in your WHERE clause.
Diya Ayesa 21-Oct-13 11:18am    
i change it but when i login through computer science admin then it still shows me all documents??
Diya Ayesa 21-Oct-13 11:22am    
how i done this with userid? beacuse i define users through departments like which user is link to which department
ZurdoDev 21-Oct-13 11:27am    
Then pass in user id and join to the users table to get the department id.

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