Can you pass an undeclared variable to a Stored Procedure

  • If I have a SP that calls another/different SP can I pass to that second SP a variable that has not been declared within the 1st SP and which was not passed to the 1st SP like the below?  I am walking through some code in a SP and found that it had a variable not cleared anywhere and I didn't think this was possible but the SP works. Below is a very hyphenated version of the SP. It does far more that what is below but I'm only asking about passing in a variable not declared anywhere and not anything the SP itself is doing.

    thanks

    EXAMPLE:

    CREATE PROCEDURE dbo.UL_moveOut ( @p_hTenant NUMERIC )
    AS
    DECLARE @k_iCharge NUMERIC
    BEGIN
    SET @k_iCharge = 7

    EXECUTE UL_batch_header @p_iType = @k_iCharge
    END

    Kindest Regards,

    Just say No to Facebook!
  • The @p_iType is declared in the called proc as a parameter.

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • YSLGuru please provide the beginning to the UL_batch_header stored procedure as that would greatly complete the picture of what you are asking about. Otherwise, I concur with ScottPletcher assessment although I also concur that does not sound like what you were describing to be the case.

Viewing 3 posts - 1 through 2 (of 2 total)

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