1

I have a SQL Script with the following line

declare @input varchar(20)
Select * from Employees where [dept] = @input

What I want is When I execute the above script in SQL 2005 I want to prompt for an input By opening an inputbox etc., such that the value is accepted in '@input' variable and so the user retrieves the records giving dynamic inputs.

2
  • 1
    SQL is SQL. The RDBMS doesn't prompt the user, it performs given queries written in SQL. You must be confusing it with Access, which is a hybrid between a document, GUI application and database. Commented Nov 15, 2010 at 7:45
  • 4
    +Unless you learn to !accept! given answers, you will receive few good ones. Commented Nov 15, 2010 at 7:46

4 Answers 4

1

You can't do that. The database doesn't have a user interface, so there are no means of prompting for a value.

You have to make an application that prompts for the value, queries the database and displays the result.

Sign up to request clarification or add additional context in comments.

Comments

1

You're really asking for a nonexistent feature but there are a few workarounds:

  • SSRS allows you to define a "report" with parameters that will take the form of input boxes etc for your users.
  • If you're ok with the users using SSMS, create the query as a stored procedure and have them use the execute option in the left-hand tree (this prompts for parameter inputs).

Comments

1

Here's what you want
Accepting User Input

But it's for Oracle( ! ) . I hope this will work for other dbs also

2 Comments

Delete this answer. It's for Oracle. And it's a bad habit too.
I hope this will work for other dbs also - NO. it's a bad habit. RDBMS is a SERVER. it accepts connections, like an API. You give the request, receive the response. The SERVER can't make your PC (which may run a Mac OS, Linux, FreeBSD, Windows or whatever) to open up a dialog of some sort. It's just WRONG. It's missing the point, it's mixing up concerns. Unacceptable in any form.
0

Or use C#; Rapid Application Development Using SQL Server 2005 Compact Edition and Visual C#.NET

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.