Setting variables in SQL functions/probs

前端 未结 3 726
挽巷
挽巷 2020-12-12 07:31

Assume I have a normal SQL procedure which has a few arguments.

During debugging it would be nice if i could assign some values to these arguments so that I can just

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-12 07:51

    If you're going to do this, I suggest you consider adding a @Debug parameter to your procedures:

    create procedure dbo.SomeProc @p1 int, @p2 int, @Debug bit = 0x0
    as
    set nocount on
    begin
    
    if @Debug = 0x1 -- set test values only if debugging
    begin
    print 'Start debugging'
    set @p1 = 1
    set @p2 = 2
    end
    
    /* your code continues here... */
    
    end
    

    Then when you want to test your code, just execute the procedure with @Debug = 0x1 to execute the debugging code.

提交回复
热议问题