Passing arguments for stored procedures IN
-
Hi, i am having a stored procedure like this: CREATE PROCEDURE SP1 @arg1 varchar(100) select * from emp where empid in (@arg1) the argument @arg1 will depend on the user's choice in the front end. An example of this argument may look like this: 'emp1','emp2','emp6' My problem is "I am unable to pass this type of argument for executing the stored procedure" Please help. Thank You. Please Plant Trees to Save the Mother Earth.
-
Hi, i am having a stored procedure like this: CREATE PROCEDURE SP1 @arg1 varchar(100) select * from emp where empid in (@arg1) the argument @arg1 will depend on the user's choice in the front end. An example of this argument may look like this: 'emp1','emp2','emp6' My problem is "I am unable to pass this type of argument for executing the stored procedure" Please help. Thank You. Please Plant Trees to Save the Mother Earth.
-
Hi, i am having a stored procedure like this: CREATE PROCEDURE SP1 @arg1 varchar(100) select * from emp where empid in (@arg1) the argument @arg1 will depend on the user's choice in the front end. An example of this argument may look like this: 'emp1','emp2','emp6' My problem is "I am unable to pass this type of argument for executing the stored procedure" Please help. Thank You. Please Plant Trees to Save the Mother Earth.
Would that work in a languge like C# or VB.NET? For example, if I had some code like this:
public void DoStuff(string arg)
{
if (arg)
{
DoSomething();
}
else
{
DoSomethingElse();
}
}where arg is:
(this.someField == "Hello") || (this.someOtherField == "World"))
No? So why do people seem to think that kind of thing should work in SQL. (Sorry, I just see this question over and over on various forums) ColinMackay.net Scottish Developers are looking for speakers for user group sessions over the next few months. Do you want to know more? -
Hi, i am having a stored procedure like this: CREATE PROCEDURE SP1 @arg1 varchar(100) select * from emp where empid in (@arg1) the argument @arg1 will depend on the user's choice in the front end. An example of this argument may look like this: 'emp1','emp2','emp6' My problem is "I am unable to pass this type of argument for executing the stored procedure" Please help. Thank You. Please Plant Trees to Save the Mother Earth.
Possible solutions: * You could pass in multiple arguments. * You could create some dynamic sql, concatenating strings together and executing it. (Not recommended unless you absolutely have no other viable solution as it is a security risk) ColinMackay.net Scottish Developers are looking for speakers for user group sessions over the next few months. Do you want to know more?
-
Hi, i am having a stored procedure like this: CREATE PROCEDURE SP1 @arg1 varchar(100) select * from emp where empid in (@arg1) the argument @arg1 will depend on the user's choice in the front end. An example of this argument may look like this: 'emp1','emp2','emp6' My problem is "I am unable to pass this type of argument for executing the stored procedure" Please help. Thank You. Please Plant Trees to Save the Mother Earth.
This worked fine for me:
create proc SP1 @arg1 varchar(100) as select @arg1 = 'select * from emp where empid in(' + @arg1 +')' exec (@arg1)
---------- There go my people. I must find out where they are going so I can lead them. - Alexander Ledru-Rollin -
This worked fine for me:
create proc SP1 @arg1 varchar(100) as select @arg1 = 'select * from emp where empid in(' + @arg1 +')' exec (@arg1)
---------- There go my people. I must find out where they are going so I can lead them. - Alexander Ledru-RollinBut remember, there are security issue using dynamic SQL execution. ColinMackay.net Scottish Developers are looking for speakers for user group sessions over the next few months. Do you want to know more?