Nanda
Nanda

Reputation: 614

User inputs to sql script

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.

Upvotes: 1

Views: 10419

Answers (4)

vettipayyan
vettipayyan

Reputation: 3308

Here's what you want
Accepting User Input

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

Upvotes: 1

Stefan Mai
Stefan Mai

Reputation: 23949

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).

Upvotes: 1

Guffa
Guffa

Reputation: 700552

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.

Upvotes: 1

Related Questions