• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 837
  • Last Modified:

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
0
gabbs1
Asked:
gabbs1
  • 2
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
create view YourView
as
select *
from yourtable
where suser_sname() = 'user2'
or FinalFieldCol = 0

CHeers
0
 
geotigerCommented:
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:
geotiger, are you sure ?
>>if user2 then view all records.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now