|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now! |
|
#1
|
|||
|
|||
|
Search all tables with a string
I'm trying to get a page to search my entire database with a search term. The problem is that the information is in seven different tables. Here's the code I'm using to write the SQL. Another recordset is feeding the table names into this code.
Code:
<%
dim unionizer
While (NOT dropdown1.EOF)
If Left(dropdown1.Fields.Item("Name").Value, 4) = "MSys" Then
dropdown1.MoveNext()
Else
unionizer = unionizer + "SELECT * FROM " + dropdown1.Fields.Item("Name").Value + " WHERE fnAddress = 'varString' UNION ALL "
dropdown1.MoveNext()
End If
Wend
If (dropdown1.CursorType > 0) Then
dropdown1.MoveFirst
Else
dropdown1.Requery
End If
%>
Am I doing this right? Or is there a better way? Also, instead of fnAddress can I use a wildcard (i.e. SELECT * FROM * WHERE * = variable). All I want to do is search the whole database with a string and have it return all the records containing the string. Thanks for any help! Scott |
|
#2
|
|||
|
|||
|
your the second person to post this question on this forum..and I still don't understand why you need to search throught ALL the fields of many tables?
here's a few pointers for you: 1- try to do a view with all your table 2-do a SP and search your table one at a time and do a while loop on the field with the function COL_name(table id, column id) to get the name of the field from a table x 3-try to read about Execute function in book -online...it permit you to build SQl string at run-time |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > Search all tables with a string |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|