简体   繁体   中英

Change variable within SQL Server stored procedure

I'm running a simple while loop that executes a stored procedure given a condition. Is there any way to access the stored procedure variable and change a variable within it before it executes? The variable I want to change is the same as the @date variable.

Thanks for any help guys.

declare @dayscount int
Declare @date as date

set @dayscount = 256
set @date = cast(GETDATE() - @dayscount as Date);

while (@dayscount >= 1)
   exec A

set @dayscount = @dayscount - 1

如果您所要做的只是在存储过程中递减或动态sql,并使用replace函数将变量替换为所需的值,然后在存储过程中运行execute_sql存储过程,则可以尝试在CTE中进行递归。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM