Solved

How find value in any column?

Posted on 2007-11-30
2
225 Views
Last Modified: 2010-04-23
USE CompanyA SELECT * FROM EccUser WHERE Administrator='Y'

With that code, I can sql query the EccUser table for those with admin status. I am checking the Administrator column for Y values.

Is there a way to do a query on all columns for a specified value? Like this if it worked:

USE CompanyA SELECT * FROM EccUser WHERE 'Y'
0
Comment
Question by:Pizpot
2 Comments
 
LVL 9

Accepted Solution

by:
nito8300 earned 125 total points
ID: 20385161
Do you mean using a OR statement?

USE CompanyA SELECT * FROM EccUser WHERE columnA = 'Y' OR columnB = 'Y' OR columnC = 'Y'

Nito
0
 
LVL 8

Assisted Solution

by:i2mental
i2mental earned 125 total points
ID: 20385191
OR would be the most direct way. It is possible to create a loop through each of the columns using SYSCOLUMNS if this code had to be portable between tables or span multiple tables or perhaps had so many columns that it were more work to type every column name.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Round up to 100% in .NET 10 46
Sql query 34 22
DATETIMEOFFSET feature 1 5
Stored Procedure 2 10
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
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 extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now