Stored procedure call syntax

  • When calling stored procedures with input parameters, do I need to declare variables or not before the execute command, I don't usually, but I see in SSMS when generating the script for execute sproc, it declares all the variables before call the sproc.

  • Depends what you're doing, where the values for the proc come from, whether there are output procedures, etc.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • I just do a simple call to a stored procedure with 3 input parameters in ssms,

    no output value.

    for example I just want to execute sp_WhoIsActive with some input parameters in SSMS,

    and it returns the result at the grid. I guess it is not requried to declare parameters data type, unless it will reused after execute statement, is that correct?

    In SSMS, when generating script, it always declare the datatype of parameters, so wondered if it is required.

    Thanks

  • I let SSMS generate the script to run a stored proc, and I get this:

    DECLARE @rc int

    DECLARE @DDVersion varchar(20)

    -- TODO: Set parameter values here.

    EXECUTE @rc = [cidne2110].[dbo].[spDDAddFixAll]

    @DDVersion

    GO

    I edit the code like this, then execute it:

    DECLARE @rc int

    DECLARE @DDVersion varchar(20) = '2.1.10'

    -- TODO: Set parameter values here.

    EXECUTE @rc = [cidne2110].[dbo].[spDDAddFixAll]

    @DDVersion

    GO

    This would be the same thing:

    EXECUTE dbo.spDDAddFixAll '2.1.10'

    GO

  • Thanks, yes, I tried those earlier and knew they all work, but just want to confirm my question on my previous post.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply