Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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 highlight the body of the proc and execute it (as opposed to manually replace the variable with values.

Is there any way to do this? I tried:

@Date1 datetime,
@Date2 datetime

SET @Date1 = '2012-03-23'

but it doesn't like it??

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
407 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...