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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Searching for data in a table...HOW?

Author  Topic 

brendalisalowe
Constraint Violating Yak Guru

269 Posts

Posted - 2004-08-03 : 18:46:42
There is going to be data put into a textbox and I need to be able to search through a SQL Server table and have it find it then return that record. Does anyone know how to do that? I have NEVER done it before. Any help would be GREAT! Thanks!

Brenda

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2004-08-03 : 19:09:19
HTML texbox? ASP?
<%
Search = TRIM(Request.Form("Search"))
IF Search <> "" THEN
SQL = "SELECT * FROM table WHERE Field LIKE '%" & Search & "%'"
Set RS = Conn.Execute(SQL)
IF NOT RS.EOF THEN
WHILE NOT RS.EOF
Response.Write("<BR>" & RS("Field1")
Response.Write("<BR>" & RS("Field2")
RS.MoveNext
WEND
END IF
END IF
%>
Go to Top of Page

ditch
Master Smack Fu Yak Hacker

1466 Posts

Posted - 2004-08-03 : 20:58:51
another option would be to use charindex instead of like (This is my preffered method)

SQL = "SELECT * FROM table WHERE CHARINDEX(Field, '" & Search & "') > 0"


Duane.
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-08-04 : 04:37:37
or you can enable full text search in your db...

Go with the flow & have fun! Else fight the flow :)
Go to Top of Page
   

- Advertisement -