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 more parameters to stored procedure

Passing more parameters to stored procedure

Scheduled Pinned Locked Moved Database
questiondatabasetutorial
4 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.
  • S Offline
    S Offline
    Siva Myneni
    wrote on last edited by
    #1

    Hi All, I have a question for you? I have to pass 7 parameters to the procedure. for some parameters i am not passing a value. how to do this?

    sivamyneni

    A E 2 Replies Last reply
    0
    • S Siva Myneni

      Hi All, I have a question for you? I have to pass 7 parameters to the procedure. for some parameters i am not passing a value. how to do this?

      sivamyneni

      A Offline
      A Offline
      andyharman
      wrote on last edited by
      #2

      You need to supply defaults for each of your optional parameters:

      create procedure MyProc
      @Param1 varchar(10) = null,
      @Param2 int = null,
      @Param3 date = null
      as begin
         set nocount on
         --do stuff
         return(0)
      end
      go
      
      exec MyProc
      exec MyProc 'hello', 123, '1 feb 2007'
      exec MyProc 'world'
      exec MyProc @Param3 = '1 feb 2007'
      

      Hope this helps. Andy

      S 1 Reply Last reply
      0
      • A andyharman

        You need to supply defaults for each of your optional parameters:

        create procedure MyProc
        @Param1 varchar(10) = null,
        @Param2 int = null,
        @Param3 date = null
        as begin
           set nocount on
           --do stuff
           return(0)
        end
        go
        
        exec MyProc
        exec MyProc 'hello', 123, '1 feb 2007'
        exec MyProc 'world'
        exec MyProc @Param3 = '1 feb 2007'
        

        Hope this helps. Andy

        S Offline
        S Offline
        Siva Myneni
        wrote on last edited by
        #3

        Hi I tried that one i am not getting proper result because none of my field contaains null value.so i am not getting the desired.

        sivamyneni

        1 Reply Last reply
        0
        • S Siva Myneni

          Hi All, I have a question for you? I have to pass 7 parameters to the procedure. for some parameters i am not passing a value. how to do this?

          sivamyneni

          E Offline
          E Offline
          Elina Blank
          wrote on last edited by
          #4

          Try this: If Your procedure is like following: ALTER PROCEDURE myProcedure @Param1 int = 0, @Param2 int = 0, @Param3 int, @Param4 int = 0, @Param5 int = 0, @Param6 int, @Param7 int AS -- Procedure code In order to call it (say, from another sp): exec myProcedure @Param3 = @PassedParam1, @Param6 = @PassedParam2, @Param7 = @PassedParam3 Note: Initialize parameters in the original procedure if you are not sure, the procedure will get those parameters passed to it. (In the case above, if you will not pass one of the @Param3, @Param6, or @Param7) the error will happen. Hope that helps.

          Sincerely, Elina Life is great!!! Enjoy every moment of it! :-O

          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