using suser_sname() in a view to get data.

Posted on 2004-09-29
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 143

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 1000 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 143

Expert Comment

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

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

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
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Suggested Courses

741 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