Bonjour,
voici une requête case / when qui doit retourné un résultat différents dans la variable NEW_SIGNAL en fonction de la valeur du champ ART_STAT3. Dans mon exemple le résultat devrait être 'TEST' mais il renvoi NULL.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
declare @newsignaletique varchar(1000),@text_signaletique varchar(1000)
declare @table table (Code_Art varchar(15),stat3 varchar(10))
declare @table1 table (Code_Art1 varchar(15),new_Signaletique varchar(1000))
 
insert into @table(Code_Art,stat3)
(select art_code,art_stat3
from ERP_PROD..ER2.GCARTICLE
where art_rub4 ='0029');
 
select *
from @table;--Visu
 
 
set @text_signaletique = 'TEST'
set @newsignaletique = 
(select top 1
 
case
when ART_STAT3 = 'SSAT' and @text_signaletique not like '%Conditionné%' then CONCAT(@text_signaletique,' .','Conditionné ',stat_libelle)
when ART_STAT3 = 'SSVID' and @text_signaletique not like '%Conditionné%' then CONCAT(@text_signaletique,' .','Conditionné ',stat_libelle)
when ART_STAT3 = 'SSAT' and @text_signaletique like '%Conditionné%' then @text_signaletique
when ART_STAT3 = 'SSVID' and @text_signaletique like '%Conditionné%' then @text_signaletique
else @text_signaletique
end as NEW_SIGNAL
 
from ERP_PROD..ER2.GCCODE_STAT,ERP_PROD..ER2.GCARTICLE,@table
where GCCODE_STAT.STAT_CODE = GCARTICLE.ART_STAT3
and  GCARTICLE.ART_CODE = Code_Art
and GCCODE_STAT.STAT_TYPE = 'A' and GCCODE_STAT.STAT_NIVEAU = 3
and GCARTICLE.ART_CODE in (select Code_Art from @table));
 
select @newsignaletique NEW_SIGNAL;--Visu
 
insert into @table1(Code_Art1,new_Signaletique)
select Code_Art,@newsignaletique
from @table;
 
select *
from @table1;--Visu
Nom : Annotation 2020-03-10 124504.png
Affichages : 184
Taille : 8,4 Ko

Qu'est-ce qui cloche dans ma requête ??
Merci de votre aide