Solved

using suser_sname() in a view to get data.

Posted on 2004-09-29
4
797 Views
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:

x,x,x,x,0
x,x,x,x,0
x,x,x,x,1

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 :)

Thanks
0
Comment
Question by:gabbs1
  • 2
4 Comments
 
LVL 143

Expert Comment

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

CHeers
0
 
LVL 12

Accepted Solution

by:
geotiger earned 250 total points
ID: 12182409
It should be

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

Expert Comment

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

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
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 shrink a transaction log file down to a reasonable size.

820 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