MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old March 24th, 2004, 05:23 PM
dirtyirishhooer dirtyirishhooer is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 13 dirtyirishhooer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 6 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old March 24th, 2004, 06:49 PM
sypher sypher is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Montreal
Posts: 92 sypher User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 10 sec
Reputation Power: 5
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Search all tables with a string


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway