Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 275
  • Last Modified:

How find value in any column?

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
Pizpot
Asked:
Pizpot
2 Solutions
 
nito8300Commented:
Do you mean using a OR statement?

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

Nito
0
 
i2mentalCommented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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