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.
Author |
Topic |
Randjana
Starting Member
9 Posts |
Posted - 2008-01-31 : 06:51:54
|
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
282 Posts |
Posted - 2008-01-31 : 06:58:45
|
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 |
|
|
Randjana
Starting Member
9 Posts |
Posted - 2008-01-31 : 07:11:31
|
wow it seems to be really complex i'll try to figure it out. |
|
|
pravin14u
Posting Yak Master
246 Posts |
Posted - 2008-01-31 : 08:56:32
|
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 |
|
|
pootle_flump
1064 Posts |
Posted - 2008-01-31 : 09:18:13
|
How come you don't know which column the value will be in? Do you have this normalised to first normal form? |
|
|
m_casamayor
Starting Member
8 Posts |
Posted - 2008-01-31 : 11:53:08
|
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... |
|
|
jdaman
Constraint Violating Yak Guru
354 Posts |
Posted - 2008-01-31 : 12:13:33
|
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 |
|
|
|
|
|