Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
how to take user input in pl/sql of sql server 2005
please give me a example
Posted
Comments
[no name] 13-Jul-12 15:13pm    
Your question is not at all clear. Please elaborate.
adilmemon 13-Jul-12 15:20pm    
means if i have query like
select * from employee where salary>=input
input variable value should be taken from user
[no name] 13-Jul-12 15:25pm    
And? You are not making any sense. Is your question how do you get input from users to input into a query? The answer is the same way you get inpput from users for anything else. It's up to you and your design.
adilmemon 13-Jul-12 15:32pm    
ya i want to take input from user
but in pl/sql first declare the variable
then take the input
e.g.
DECLARE @input int
begin
select * from employee where salary>=input
end
like that

You should use Parametrized query to take input from user and then retrieve data.
Sample:
C#
// Update the name of a customer, which is passed by user
// customerID passed by you to DB as integer value
// inputCustomerName passed by you to DB as string value
string commandText = "UPDATE Store SET CustomerName = @custName WHERE CustomerID = @ID;";

using (SqlConnection connection = new SqlConnection(connectionString))
{
        SqlCommand command = new SqlCommand(commandText, connection);
        command.Parameters.Add("@ID", SqlDbType.Int);
        command.Parameters["@ID"].Value = customerID;

        // Use AddWithValue to assign customer name.
        command.Parameters.AddWithValue("@custName", inputCustomerName);

        try
        {
            connection.Open();
            Int32 rowsAffected = command.ExecuteNonQuery();
            Console.WriteLine("RowsAffected: {0}", rowsAffected);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
}

Look here for parameterized query and it's usage:
MSDN: Configuring Parameters and Parameter Data Types (ADO.NET)[^]
MSDN: DataAdapter Parameters (ADO.NET)[^]
MSDN: SqlCommand.Parameters Property [^]
 
Share this answer
 
From your comments it sound like you want to know how to write a stored procedure.
http://msdn.microsoft.com/en-us/library/ms345415.aspx[^]
 
Share this answer
 
Comments
adilmemon 13-Jul-12 15:42pm    
no i want it input in pl/sql statement
[no name] 13-Jul-12 15:45pm    
now you are back to making no sense at all. what is it that you mean by "input in pl/sql statement"?
adilmemon 13-Jul-12 15:48pm    
after declaring variable
can we take variable value from user in sql server 2005 or not
DECLARE @input int
begin
select * from employee where salary>=input
end

that is taking value for input variable
[no name] 13-Jul-12 15:51pm    
Repeating the same thing over and over that does not make sense does not tell me anything. What you are describing is writing and using a stored procedure! That is where you DECLARE @input and use it in queries.
adilmemon 14-Jul-12 11:57am    
i want take input variable value from user
how can i take just like i am taking in oracle 10g pl/sql

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900