1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
alter function REACH_TestCalcul2()
returns @TCalcul TABLE
([Article] [nchar](15) NULL,[Substance] [int] NULL,[Poids] [real] NULL)
AS
BEGIN
Declare @Art nchar(15)
Declare @Sub int
Declare @typ bit
Declare @Val real
Declare @Res real
Declare @TEMPArt nchar(15)
Declare @TEMPVal real
begin /* Liste tous les Enregistrements de la table TEMP un par un */
Declare C_TEMP CURSOR For
select Article, Valeur from REACH_Temp1
open C_TEMP
Fetch C_TEMP into @TEMPArt,@TEMPVal
While (select fetch_status from sys.dm_exec_cursors(0) where name='C_TEMP') = 0
/* Insertion dans la table */
begin
Declare C_NOMEN CURSOR For
select Article, Substance,typedemesure,valeur from REACH_NomenclatureSubstances
where article = @TEMPArt
select @Res=0
open C_NOMEN
Fetch C_NOMEN into @Art,@Sub,@Typ,@Val
While (select fetch_status from sys.dm_exec_cursors(0) where name='C_NOMEN') = 0
Begin
if @Typ=1
begin
select @Res=@TEMPVal
insert into @TCalcul(article,substance,poids) values (@Art,@Sub,@Res)
end else
begin
select @Res=(@Val * @TEMPVal)/100
insert into @TCalcul(article,substance,poids) values (@Art,@Sub,@Res)
end
Fetch C_NOMEN into @Art,@Sub,@Typ,@Val
end
Close C_NOMEN
Deallocate C_NOMEN
end
/* FIN Insertion dans la table */
Fetch C_TEMP into @TEMPArt,@TEMPVal
end /* FIN de Liste tous les Enregistrements de la table TEMP un par un */
Close C_TEMP
Deallocate C_TEMP
RETURN
end |
Partager