Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Column Wild Card in Where statement

Author  Topic 

Draconis_KoHF
Starting Member

1 Post

Posted - 2009-02-05 : 12:57:06
I have a table with about 10 columns of people's names (Engineer Name, Manager Name, Designer Name, Drafter Name, Shop Name, Painter Name...). We want to do a search page that will return results when they enter a name to search by. Is there a easy way to do a search statement like
SELECT * FROM tblNames WHERE (* LIKE '%John%')

I would like to keep from listing all the columns and it's where clase (WHERE [Manager] LIKE '%John%' OR [Engineer] LIKE '%John%' OR [Designer] LIKE '%John%' OR [Drafter] LIKE ...)

Thanks.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-05 : 13:01:41
http://www.mssqltips.com/tip.asp?tip=1522
Go to Top of Page

tonymorell10
Yak Posting Veteran

90 Posts

Posted - 2009-02-05 : 16:23:48
You could create a simple view to give you a list of the names and Titles:


CREATE VIEW vw_Names
AS
SELECT 'Engineer' As Title, [Engineer Name] As [Name] FROM tblNames
UNION ALL
SELECT 'Manager', [Manager Name] FROM tblNames
UNION ALL
SELECT 'Designer', [Designer Name] FROM tblNames
UNION ALL
SELECT 'Drafter', [Drafter Name] FROM tblNames
UNION ALL
SELECT 'Shop', [Shop Name] FROM tblNames
UNION ALL
SELECT 'Painter', [Painter Name] FROM tblNames
GO


SELECT Title, [Name] FROM vw_Names
WHERE [Name] LIKE '%John%'
Go to Top of Page
   

- Advertisement -