User Input for a query

G

Guest

How can I get a user input for a query. The users input will be used in the
"where" field.

For the example below, user will type the name of the student.

Select Rank, Score, School From StudentRecord Where Name={{User inputs the
name when the query is run}}

Thanks
 
G

Guest

Use

Select Rank, Score, School From StudentRecord Where [Name]=[ Please enter
name]

Also you can use
Select Rank, Score, School From StudentRecord Where [Name]=[ Please enter
name] Or [ Please enter name] Is Null

to display all the records if the user didn't write a name
 
G

Guest

Ofer Cohen said:
Use

Select Rank, Score, School From StudentRecord Where [Name]=[ Please enter
name]

Also you can use
Select Rank, Score, School From StudentRecord Where [Name]=[ Please enter
name] Or [ Please enter name] Is Null

You can also use (aircode):

SELECT Rank, Score, School
FROM StudentRecord
WHERE [NAME] =
IFF([Please enter name] IS NULL, [NAME], [Please enter name]);

SELECT Rank, Score, School
FROM StudentRecord
WHERE [NAME] = Nz([Please enter name], [NAME]);

SELECT Rank, Score, School
FROM StudentRecord
WHERE IIF([NAME] IS NULL, '{{NONE}}', [NAME]) =
IIF([Please enter name] IS NULL, IIF([NAME] IS NULL, '{{NONE}}', [NAME]),
[Please enter name]);

SELECT Rank, Score, School
FROM StudentRecord
WHERE Nz([NAME], '{{NONE}}') =
Nz([Please enter name], Nz([NAME], '{{NONE}}'));

PARAMETERS [Please enter name] TEXT (35);
SELECT Rank, Score, School
FROM StudentRecord
WHERE [NAME] = Nz([Please enter name], [NAME]);

CREATE PROCEDURE
(
[Please enter NAME] VARCHAR(35) = NULL
)
AS
SELECT Rank, Score, School
FROM StudentRecord
WHERE [NAME] =
IFF([Please enter name] IS NULL, [NAME], [Please enter name]);

and combinations thereof, not to mention using SWITCH and other variations...

Jamie.

--
 
G

Guest

Hello All,

I am doing something similar. On my (employee) form, I need the user to
enter either an employeeID or the employee last and first names. In my case,
clicking a "perform search"/"Submit" button should:
1. Execute the select query
2. Unhide all the previously hidden fields on the employee form and poplate
them with the data returned from the query. In my application, some fields
will remain hidden of disabled because only a few of the fields will then be
updated.
3. After updating the relevant fields, perfom an update query when the
submit button is clicked.

What other things need to be considered in such a search then update
scenerio such as this? How can I check for success or failure of the query,
that do some error trapping?

TIA,

Rich



Jamie Collins said:
Ofer Cohen said:
Use

Select Rank, Score, School From StudentRecord Where [Name]=[ Please enter
name]

Also you can use
Select Rank, Score, School From StudentRecord Where [Name]=[ Please enter
name] Or [ Please enter name] Is Null

You can also use (aircode):

SELECT Rank, Score, School
FROM StudentRecord
WHERE [NAME] =
IFF([Please enter name] IS NULL, [NAME], [Please enter name]);

SELECT Rank, Score, School
FROM StudentRecord
WHERE [NAME] = Nz([Please enter name], [NAME]);

SELECT Rank, Score, School
FROM StudentRecord
WHERE IIF([NAME] IS NULL, '{{NONE}}', [NAME]) =
IIF([Please enter name] IS NULL, IIF([NAME] IS NULL, '{{NONE}}', [NAME]),
[Please enter name]);

SELECT Rank, Score, School
FROM StudentRecord
WHERE Nz([NAME], '{{NONE}}') =
Nz([Please enter name], Nz([NAME], '{{NONE}}'));

PARAMETERS [Please enter name] TEXT (35);
SELECT Rank, Score, School
FROM StudentRecord
WHERE [NAME] = Nz([Please enter name], [NAME]);

CREATE PROCEDURE
(
[Please enter NAME] VARCHAR(35) = NULL
)
AS
SELECT Rank, Score, School
FROM StudentRecord
WHERE [NAME] =
IFF([Please enter name] IS NULL, [NAME], [Please enter name]);

and combinations thereof, not to mention using SWITCH and other variations...

Jamie.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top