using suser_sname() in a view to get data.


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
LVL 1
gabbs1Asked:
Who is Participating?
 
geotigerConnect With a Mentor Commented:
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
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
create view YourView
as
select *
from yourtable
where suser_sname() = 'user2'
or FinalFieldCol = 0

CHeers
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
geotiger, are you sure ?
>>if user2 then view all records.
0
All Courses

From novice to tech pro — start learning today.