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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 search a value in a sql table
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

9 Posts

Posted - 01/31/2008 :  06:51:54  Show Profile  Reply with Quote
dear all,

is is possible to search for a value in a sql a table?
I know that you can search for a particular value in a column,
like "select * frm table where clomn1 = 'test'"

what about select * from table where value = 'test'?
do you have to declare value? and how?

can some one guide me on this please?

Constraint Violating Yak Guru

282 Posts

Posted - 01/31/2008 :  06:58:45  Show Profile  Reply with Quote
Are looking for dynamic column search i.e. want to pass column name as variable where the value "test" should be searched in? If that is the case, you will need dynamic sql.
Go to Top of Page

Starting Member

9 Posts

Posted - 01/31/2008 :  07:11:31  Show Profile  Reply with Quote
wow it seems to be really complex
i'll try to figure it out.
Go to Top of Page

Posting Yak Master

246 Posts

Posted - 01/31/2008 :  08:56:32  Show Profile  Click to see pravin14u's MSN Messenger address  Send pravin14u a Yahoo! Message  Reply with Quote
A small algo that I can think of if you are ready to accept a procedure to do the above task:

1. Get the list of columns in the particular table(from syscolumns)
3. Search the above colums one by one (while searching you may need to covert all the columns to VARCHAR if you use LIKE in your search query).

Someone correct me if this is not possible. Thanks
Go to Top of Page

Flowing Fount of Yak Knowledge

United Kingdom
1064 Posts

Posted - 01/31/2008 :  09:18:13  Show Profile  Reply with Quote
How come you don't know which column the value will be in? Do you have this normalised to first normal form?
Go to Top of Page

Starting Member

8 Posts

Posted - 01/31/2008 :  11:53:08  Show Profile  Reply with Quote
you can also download an open source tool called Nautilus (
1-find the table, you don't need the exact name, just part of it.
2-put the value you want to find and the tool will build the query for you. You can get the result or the query. The query is not the same if you put a numeric value or a string value ! guess why ?

3-finally, you can also find any value in any table...
Go to Top of Page

Constraint Violating Yak Guru

354 Posts

Posted - 01/31/2008 :  12:13:33  Show Profile  Reply with Quote
A modified version (just tie it to your one table instead of looking in all tables) of the procedure found here would work:
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000