[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

649 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