关于datetime类型作output参数时会加上程序执行时间的问题
use tempdbgocreate proc p_test@id datetime outputas set @id = (select dateadd(day,2,getdate()))godeclare @id datetimeset @id = (select getdate())select @idWAITFOR DELAY '00:00:05'exec p_test @id outputselect @idgodrop proc p_testgo
use tempdbgocreate proc p_test@id datetime outputas set @id = dateadd(day, 2, isnull(@id,getdate())) -- @id传入时间,NULL取getdate()godeclare @id datetimeset @id = (select getdate())select @idWAITFOR DELAY '00:00:05'exec p_test @id outputselect @idgodrop proc p_test
[解决办法]
getdate() 是不确定函数。两次执行值是不一样的,所以delay 的5秒在俩面有体现。
getdate()后一般直接存储到变量里面使用。LZ这个
WAITFOR DELAY '00:00:05'
exec p_test @id output
等待5秒后,再次的getdate()肯定是跟前面的不一样了。