[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 834
  • 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

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

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