Computer Help forum

General discussion

How to filter a table (MS Sql Server)

I have a table emps ,from this table i want to bring certain records based on login other words i want to filter rows without using condition in sql statement.i want to fix from database side.

for ex sql1 :select * from emps where mgr_id=1234
this brings all rows where mgr_id=1234. now when user 1234 login,if he use only
sql2 : select * from emps
i want to get result like above sql1.

help me please

Discussion is locked
You are posting a reply to: How to filter a table (MS Sql Server)
The posting of advertisements, profanity, or personal attacks is prohibited. Please refer to our CNET Forums policies for details. All submitted content is subject to our Terms of Use.
Track this discussion and email me when there are updates

If you're asking for technical help, please be sure to include all your system info, including operating system, model number, and any other specifics related to the problem. Also please exercise your best judgment when posting in the forums--revealing personal information such as your e-mail address, telephone number, and address is not recommended.

You are reporting the following post: How to filter a table (MS Sql Server)
This post has been flagged and will be reviewed by our staff. Thank you for helping us maintain CNET's great community.
Sorry, there was a problem flagging this post. Please try again now or at a later time.
If you believe this post is offensive or violates the CNET Forums' Usage policies, you can report it below (this will not automatically remove the post). Once reported, our moderators will be notified and the post will be reviewed.
Collapse -
(NT) (NT) try this post in the office forum as well

In reply to: How to filter a table (MS Sql Server)

Collapse -
Re: How to filter a table (MS Sql Server)

In reply to: How to filter a table (MS Sql Server)

I'm afraid that SQL server is designed to respond to SQL queries and not deliver anything other than has been asked.

What should you want SQL server to do if user 1234 asks:
select * from emps where mgr_id <> 1234

I don't know SQL-server. It might have something like a system variable username or function username(), like it probably has a way to say 'today' or 'databasename'. Then you can make a view like
myemps = select * from emps where mgr_id = :username
and tell the user to run their queries over myemps, just like they run a query over todays_orders.

Or possibly SQL server has the option to limit access to records in a table depending on values kin that records. Then you can grant (that's an sql command available to the administrator) each user access to only his own employees, and he won't see the others.

Just some thoughts.


Popular Forums

Computer Newbies 10,686 discussions
Computer Help 54,365 discussions
Laptops 21,181 discussions
Networking & Wireless 16,313 discussions
Phones 17,137 discussions
Security 31,287 discussions
TVs & Home Theaters 22,101 discussions
Windows 7 8,164 discussions
Windows 10 2,657 discussions


This one tip will help you sleep better tonight

A few seconds are all you need to get a better night's rest.