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

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

Randjana
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?

sunil
Constraint Violating Yak Guru

India
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.
see http://www.sommarskog.se/dyn-search.html
Go to Top of Page

Randjana
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

pravin14u
Posting Yak Master

India
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

pootle_flump
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

m_casamayor
Starting Member

Argentina
8 Posts

Posted - 01/31/2008 :  11:53:08  Show Profile  Reply with Quote
you can also download an open source tool called Nautilus (http://sourceforge.net/projects/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

jdaman
Constraint Violating Yak Guru

USA
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: http://vyaskn.tripod.com/search_all_columns_in_all_tables.htm
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.05 seconds. Powered By: Snitz Forums 2000