User Input Parameter for SQL Query

Posted on 2008-10-27
Last Modified: 2013-11-16
I need to create a very simple query.  I would like to return all the data from one table for a specific item.  I want the user to be prompted to enter the item id.  Below is an example of the query without letting my user enter the item.

Select * from inventory
where inventory.item_id = 'AQUA-12345'

I just want this to be generic so my user is prompted to enter the item they are looking for.
Question by:RDB1369
  • 4
  • 3
  • 2
  • +1
LVL 39

Expert Comment

ID: 22815829
I am assuming SQL 2000 based upon the tags.

You would pass a parameter in to a procedure.

create procedure up_inventory_get
 @item_ID varchar(30)
select * from inventory
where item_id = @item_id

to call it:

exec up_inventory_get @item_ID = 'AQUA-12345'

Expert Comment

ID: 22815858
from where do you run the query?

basically, you need to prompt to the user and get the input, and then bind the parameter in the below query

Select * from inventory
where item_id = ?


Author Comment

ID: 22815884
This is exactly what I have done so far, and yes you are right I am working in SQL 2000.  
However, I really wanted my user to be able to just exec the stored procedure and be asked the question  "Enter Item",   Is this possible?
LVL 39

Expert Comment

ID: 22815907

Author Comment

ID: 22815911
I am sorry I did not see the second comment when I posted my response.  I have written a procedure like Brandon suggested and I can use that, but I wanted to just have my user type in
          Exec Up_inventory_get
and then the first part of the procedure would prompt my user to enter the correct item ID.
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.


Expert Comment

ID: 22815922
i don't think you can do that since stored procedure is server-side object,

what you may do is to create a .bat (if it's in windows environment) or a shell script to achieve that
LVL 39

Accepted Solution

BrandonGalderisi earned 250 total points
ID: 23395452
I think it's time to close this question up.

You said you used a procedure like http:#22815829 and I answered your question about prompting for input in http:#22815907

Author Closing Comment

ID: 31510473
I guess this is as good as it gets
LVL 39

Expert Comment

ID: 23452199
Why the B grade?  Unfortunately, you can't do what it is you are asking to do.  I answered your question completely and accurately.

I'd like you to reconsider the grade based upon the grading suggestions here (copied from help):

What's the right grade to give?

Grading at Experts Exchange is not like school. It's more like the "10-point Must" system in professional boxing; in other words, an answer is worth an A, unless it doesn't resolve your issue. If it requires you to do a little more research, or figure out one more piece of code, then it's worth a B. If you think it's not worth a B, the custom is to offer the Experts an opportunity to earn a better grade.

Giving a higher grade has no impact on your Available Points.

Expert Comment

ID: 23568710
No Response to Expert and/or Moderator.
Force changed.
Experts Exchange Moderator

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Powershell script 13 72
How to base a filter depending on fields contents? 15 48
Get Duration of last Status Update 4 31
SSRS troubles 4 20
CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now