Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Create procedure so user can only see his records

Author  Topic 

Andrew Parsons
Starting Member

7 Posts

Posted - 2010-11-29 : 15:50:17
Hello all.

Sql express 2008 sp 2
Access 2010
Database uses odbc linked tables to the sql server.
Windows NT logins

First let me thank you for trying to help.

I have built a database where people in the field submit to the SQL server via Access 2010. Everything is working great, but I am looking for a slight change to it.

Each user from the field submits to a series of different tables. Each record they submit to each table has a field with their Windows NT login inn it. What I want to do is somehow make it so each user can only see their own records in each table based on the Windows NT login field. Of course some user will still need to see all the records. I know I can use filters in Access 2010 for this however I do not want the user to have the option to remove the filter and thus be able to see all the records.

Table information:
Table [DailyReport]
Windows NT login field in table [DailyReport] is [FluidControlLogin]

Sorry if i am doing a horrid job of explaining this, so please if you need any more info please let me know.

Thanks in advance

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-11-29 : 16:09:46
Can't you just add a WHERE clause for that column and pass in the NT login?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Andrew Parsons
Starting Member

7 Posts

Posted - 2010-11-29 : 17:10:14
How do i do that sql side?
I wuld think somthing like this:

SELECT [FluidControlLogin]
FROM [DailyReport]
WHERE [FluidControlLogin] = SYSTEM_USER()

But how do i make it do this to every table and to user i select?

Thanks



Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-11-29 : 17:12:04
You'd either add it to your code or throw a view over each table. Views are a common solution.

Does SYSTEM_USER() provide the correct login?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Andrew Parsons
Starting Member

7 Posts

Posted - 2010-11-29 : 17:14:48
Does SYSTEM_USER() provide the correct login?

FluidControlLogin has nt style login DOMAIN\USERNAME

How do i check SYSTEM_USER() and if id does provide the correct login?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-11-29 : 17:17:26
Run in SSMS: select SYSTEM_USER


Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Andrew Parsons
Starting Member

7 Posts

Posted - 2010-11-29 : 17:25:19
quote:
Originally posted by tkizer

Run in SSMS: select SYSTEM_USER



I am in SSMS, do i run it in a query or do I run a stored procedure? and how? I am so sorry I am a newb, well not that bad but close enough.

Thanks Andrew
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-11-29 : 17:27:45
SSMS is going to show your user. You need to test your client users. If they have SSMS, you can run it in a new query window.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Andrew Parsons
Starting Member

7 Posts

Posted - 2010-11-29 : 17:42:45
quote:
Originally posted by tkizer

SSMS is going to show your user. You need to test your client users. If they have SSMS, you can run it in a new query window.




Okay so i found it and it does show domain\username under Name in sysusers.

Thanks thus far
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-11-29 : 17:48:14
Cool, then throw views over your tables.

Table1

View1: SELECT ... FROM Table1 WHERE YourColumn = SYSTEM_USER

And then use View1 in the application instead of Table1.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Andrew Parsons
Starting Member

7 Posts

Posted - 2010-11-29 : 18:04:00
I understand what needs to be done, just need a tad more detail on how to throw views on tables in sql. I understand how to reference the views in Access.
thank you
Andrew
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-11-29 : 18:05:15
CREATE VIEW SomeViewName
AS
SELECT YourColumnListGoesHere
FROM SomeTableName
WHERE SomeColumnName = SYSTEM_USER

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Andrew Parsons
Starting Member

7 Posts

Posted - 2010-11-30 : 09:58:06
Thank you very much. NOW can I limit thier permmision in the master table where the view was created from?

Thank you
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-11-30 : 12:26:13
If they have any permissions on the table, remove them and then grant them the permissions on the view instead.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -