これはビューのソースです。このビューを buscacancelados という名前のプロシージャのベースとして使用します。
SELECT NUMERO FROM dbo.CTRC
WHERE (EMITENTE = 504) AND (MONTH(EMISSAODATA) = 3)
AND (YEAR(EMISSAODATA) = 2013)
このプロシージャは、セット内の欠落している数値を返します
alter proc buscarcancelado (@emp int) as
begin
set nocount on;
declare @min int --- declare the variavels to be used
declare @max int
declare @I int
IF OBJECT_ID ('TEMP..#TempTable') is not null -- Controls if exists this table
begin
drop table #TempTable -- If exist delete
end
create table #TempTable
(TempOrderNumber int)-- create a temporary table
SELECT @min = ( SELECT MIN (numero)
from controlanum with (nolock)) -- search the min value of the set
SELECT @max = ( SELECT Max (numero)
from controlanum with (nolock)) -- search the max value of the set
select @I = @min -- control where begins the while
while @I <= @max -- finish with the high number
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
この手順でView controlanumを変更したい
create proc filtraperiodo (@emp int,@mes int,@ano int)as
select numero from ctrc where
EMITENTE = 504
and MONTH (EMISSAODATA ) = 3 and YEAR (EMISSAODATA)=2013
私はこのようなものが欲しい
SELECT @min = ( SELECT MIN (numero) from filtraperiodo 504,2,2013