using suser_sname() in a view to get data.

Posted on 2004-09-29
Last Modified: 2011-09-20

I have two users logging into SQL Server and I want to use suser_sname() (if that is correct) to select data from within a view so that:

if the table data is say:


I want to create a view to:

if user1 then view all records where 0 in the final field
if user2 then view all records.

but how do you do that in a view? help :)

Question by:gabbs1
  • 2
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 12180959
create view YourView
select *
from yourtable
where suser_sname() = 'user2'
or FinalFieldCol = 0

LVL 12

Accepted Solution

geotiger earned 250 total points
ID: 12182409
It should be

create view YourView
select *
from yourtable
where (suser_sname() = 'user2'
and FinalFieldCol = 0)
(suser_sname() = 'user1'
and FinalFieldCol = 1)
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 12187710
geotiger, are you sure ?
>>if user2 then view all records.

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now