Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Passing arguments for stored procedures IN

Passing arguments for stored procedures IN

Scheduled Pinned Locked Moved Database
helpdatabasetutorial
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BSRK
    wrote on last edited by
    #1

    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.

    B C E 4 Replies Last reply
    0
    • B BSRK

      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.

      B Offline
      B Offline
      BSRK
      wrote on last edited by
      #2

      The above problem i am facing in SQL Query Analyser .

      1 Reply Last reply
      0
      • B BSRK

        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.

        C Offline
        C Offline
        Colin Angus Mackay
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        • B BSRK

          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.

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          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?

          1 Reply Last reply
          0
          • B BSRK

            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.

            E Offline
            E Offline
            Eric Dahlvang
            wrote on last edited by
            #5

            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

            C 1 Reply Last reply
            0
            • E Eric Dahlvang

              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

              C Offline
              C Offline
              Colin Angus Mackay
              wrote on last edited by
              #6

              But 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?

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups