954,566 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

SQL statement to query user input??

Hi GUys

Just wondering if any one can help me out. Basically i wnat to create an SQL query which will take the input of the user and query that specific variable:

e.g the user enetrs in a field, the value entered is assigned to variable "srch", then in my SQL query i want whatever has been entered to be pattern matched to the data stored in the database, would the query possibale be something like this:

SELECT functionme FROM MsgeTble WHERE alternme LIKE "*$srch*"

Im pretty novice in databases :confused:

Please any suggestions would be grateful! Thanks

nelly_1005
Newbie Poster
11 posts since Feb 2005
Reputation Points: 10
Solved Threads: 0
 

Hey ppl,

I also have the same problem, but I usually dont have as much time to log on here. If anybody does have the answer, plz email me at [EMAIL="husseinmohamedali@gmail.com"]husseinmohamedali@gmail.com[/EMAIL]. Thanks

HMC1991
Newbie Poster
2 posts since Jun 2006
Reputation Points: 10
Solved Threads: 0
 
Hi GUys Just wondering if any one can help me out. Basically i wnat to create an SQL query which will take the input of the user and query that specific variable: e.g the user enetrs in a field, the value entered is assigned to variable "srch", then in my SQL query i want whatever has been entered to be pattern matched to the data stored in the database, would the query possibale be something like this: SELECT functionme FROM MsgeTble WHERE alternme LIKE "*$srch*" Im pretty novice in databases :confused: Please any suggestions would be grateful! Thanks






HI...

There is 2 ways.
i) u can write in the Qurey
just u have to enter in the last field like this : [Enter the Name]
and in Criteria: u have the write the filed name
like:
[Enter the Name]
Field Name

ii) u can write in the code
set db = currentdb
set rec = db.oprecordset("Select * from MsgeTble WHERE ename = " & text1.value & "")

if not(rec.bof and rec.eof) then
rec.movefirst
while not rec.eof
text1.value = rec.field("aaa")
rec.movenext
wend
end if


*********************

kindly try this if not work than reply me...

Bye...
Rupesh

Rupeshba
Newbie Poster
4 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

You could try the following syntax:

SELECT *
FROM TABLE
WHERE FIELDNAME=?;

EZHIL_VINUJIN
Newbie Poster
2 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

You could try the following syntax:

SELECT *
FROM TABLE
WHERE FIELD=?;

EZHIL_VINUJIN
Newbie Poster
2 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

select statement
select * from table_name where column_name='&column_name';

for insert
insert into table_name values ('&column_name1','&column_name2');

nandini bk
Newbie Poster
1 post since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

Here is a piece of code that does something similar to what you want I thnk.

Dim WhereClause As String
Dim AndStr As String

AndStr = ""
If Me.SearchName <> "" Then
    WhereClause = "(FirstName like '*" & Me.SearchName & "*' OR Surname like '*" & Me.SearchName & "*')"
    AndStr = " AND "
End If
If Me.SearchSuburb <> "" Then
    WhereClause = WhereClause & AndStr & "Suburb like '*" & Me.SearchSuburb & "*'"
    AndStr = " AND "
End If
If Me.SearchCompany <> "" Then
    WhereClause = WhereClause & AndStr & "CompanyName like '*" & Me.SearchCompany & "*'"
    AndStr = " AND "
End If

If Me.searchRep <> "" Then
    WhereClause = WhereClause & AndStr & "Rep='" & Me.searchRep & "'"
        AndStr = " AND "
End If

If Me.SearchStatus <> "" Then
    WhereClause = WhereClause & AndStr & "Status='" & Me.SearchStatus & "'"
    AndStr = " AND "
End If
PerformSearch:
Me.Filter = WhereClause
Me.FilterOn = True
ChrisPadgham
Posting Pro in Training
413 posts since Sep 2009
Reputation Points: 102
Solved Threads: 78
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: