我在 SQL Server 2008 中有这个 T-SQL 过程:
create procedure rolledback as
begin
set nocount on ;
declare @min int
declare @max int
declare @I INT
IF OBJECT_ID ('TEMDB..#TempTable') IS NOT NULL
begin
drop table #TempTable
end
create table #TempTable
( TempOrderNumber int )
SELECT @min = ( SELECT MIN (numero)
from controlanum with (nolock))
SELECT @max = ( SELECT Max (numero)
from controlanum with (nolock))
select @I = @min
while @I <= @max
begin
insert into #TempTable
select @I
select @I = @I + 1
end
select tempordernumber from #TempTable
left join controlanum O with (nolock)
on TempOrderNumber = o.numero where o.numero is null
end
这与视图控件完美配合,但我需要选择日期间隔
我已经写了另外两个程序来过滤这个时期
create proc maxiN (@emp int, @mes int, @ano int)
as
select Max (numero)
from ctrc
WHERE (EMITENTE = @emp)
AND (MONTH(EMISSAODATA) = @mes) AND (YEAR(EMISSAODATA) = @ano)
create proc Minix (@emp int, @mes int, @ano int)
as
select Min (numero)
from ctrc
WHERE (EMITENTE = @emp)
AND (MONTH(EMISSAODATA) = @mes) AND (YEAR(EMISSAODATA) = @ano)
我已经在程序中插入了这些程序rolledback
,但是现在rollback2返回0有点问题,就像max和min的程序返回任何东西一样。
create procedure rolledback2 ( @emp int, @mes int, @ano int) as
begin
set nocount on ;
declare @min int
declare @max int
declare @I INT
IF OBJECT_ID ('TEMDB..#TempTable') IS NOT NULL
begin
drop table #TempTable
end
create table #TempTable
( TempOrderNumber int )
exec @min = min2 @emp,@mes ,@ano
exec @min = min2 @emp,@mes ,@ano
select @I = @min
while @I <= @max
begin
insert into #TempTable
select @I
select @I = @I + 1
end
select tempordernumber from #TempTable
left join controlanum O with (nolock)
on TempOrderNumber = o.numero where o.numero is null
end
和功能不返回任何东西
declare @min int
select @min = fmin 504,2,2013
只能这样工作
fmin 504,2,2013
感谢任何方向
亚历杭德罗