Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

User Input Parameter for SQL Query

Posted on 2008-10-27
10
Medium Priority
?
542 Views
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.
0
Comment
Question by:RDB1369
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 39

Expert Comment

by:BrandonGalderisi
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)
as
select * from inventory
where item_id = @item_id
go


to call it:

exec up_inventory_get @item_ID = 'AQUA-12345'
0
 
LVL 9

Expert Comment

by:jamesgu
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 = ?

0
 

Author Comment

by:RDB1369
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?
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 22815907
No.  
0
 

Author Comment

by:RDB1369
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.
0
 
LVL 9

Expert Comment

by:jamesgu
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
0
 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 1000 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
0
 

Author Closing Comment

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

Expert Comment

by:BrandonGalderisi
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.
0
 
LVL 1

Expert Comment

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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

580 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