/*<VERSION_MINIMUM>10.31af</VERSION_MINIMUM>*/
delete from <PREFIXE_DW>EVALUATIONS
<SEPARATEUR>
insert into <PREFIXE_DW>EVALUATIONS (EVA_ID_CAMPAGNE,EVA_LIBELLE_CAMPAGNE,EVA_CODE_THEME,EVA_LIBELLE_THEME,EVA_ID_QUESTION,EVA_LIBELLE_QUESTION,EVA_NOTE,
EVA_CODE_FOURNISSEUR,EVA_RAISON_SOCIALE,EVA_CODE_NOTEUR,EVA_NOM_NOTEUR,EVA_COMMENTAIRE,EVA_CODE_PERIODE,EVA_STATUT,EVA_CODE_CREE_PAR,EVA_TYPE_REPONSE,
EVA_DATE_CREATION,EVA_DATE_VALIDITE,EVA_DATE_FIN,EVA_DATE_REPONSE,EVA_DESCRIPTION,EVA_CODE_STATUT,EVA_CREE_PAR,EVA_POIDS,EVA_PROFIL_NOTEUR,
EVA_COMMENTAIRE_AUTORISE,EVA_REGLE_COMMENT_OBLIGATOIRE,EVA_REPONSE,EVA_TERMINEE) 
select e.ID_CAMP,e.LIBELLE,rep.ID_THEME,th.LIB_THEME,rep.ID_QUEST,q.LIB_QUEST ,rep.NOTE,rep.CODE_FOU,isnull(four.RS,' '),rep.COD_NOTEUR,
isnull(u.NOM,''),
rep.COMMENTAIRE,
e.COD_PER,e.STATUT,e.CREEEPAR,q.TYPE_REP,
case when isdate(e.DTECREAT)=1 then  e.DTECREAT end ,
case when isdate(e.DTEVALID)=1 then  e.DTEVALID end ,
case when isdate(e.DTEFIN)=1 then  e.DTEFIN end ,
case when isdate(rep.DTE_REP)=1 then  rep.DTE_REP end,
e.DESCRIPT,
e.STATUT,
e.CREEEPAR,
q.POIDS,
q.PROFNOTEUR2,
case when q.AUTHCOMMENT=0x54 then 1 else 0 end,
q.REGCOMOBLIG,
isnull( r.TXT_REP ,' ') ,
case when rep.TERMINE=0x54 then 1 else 0 end
from <PREFIXE_HA>CAMP_REP_QST rep
left outer join <PREFIXE_HA>CAMP_ENT e on e.ID_CAMP=rep.ID_CAMP
left outer join <PREFIXE_HA>CAMP_QST_TH th on th.ID_CAMP=e.ID_CAMP and th.ID_THEME=rep.ID_THEME
left outer join <PREFIXE_HA>CAMP_QST_Q q on q.ID_CAMP=e.ID_CAMP and q.ID_THEME=rep.ID_THEME and q.ID_QUEST=rep.ID_QUEST
left outer join <PREFIXE_HA>CAMP_QST_R r on r.ID_CAMP=rep.ID_CAMP and rep.ID_THEME=r.ID_THEME and rep.ID_QUEST=r.ID_QUEST  and rep.REP_TAB=r.ID_REP
left outer join <PREFIXE_HA>FOURNISS four on rep.CODE_FOU=four.CODE
left outer join <PREFIXE_HA>HASTUTIL u on rep.COD_NOTEUR=u.CODE

<SEPARATEUR>
/*Removing RC*/
update <PREFIXE_DW>EVALUATIONS set EVA_COMMENTAIRE=replace(replace(EVA_COMMENTAIRE, char(13), ' '), char(10), ' ') ,EVA_DESCRIPTION=replace(replace(EVA_DESCRIPTION, char(13), ' '), char(10), ' ') 

<SEPARATEUR>
update eva set EVA_REPONSE=case when (REP_LOG=0x54 ) then '1' else '0' end 
from <PREFIXE_DW>EVALUATIONS eva, <PREFIXE_HA>CAMP_REP_QST rep where eva.EVA_TYPE_REPONSE='L' 
and EVA_ID_CAMPAGNE=rep.ID_CAMP and eva.EVA_CODE_THEME=rep.ID_THEME and eva.EVA_ID_QUESTION=rep.ID_QUEST
<SEPARATEUR>
update eva set EVA_REPONSE=rep.REP_NUM
from <PREFIXE_DW>EVALUATIONS eva, <PREFIXE_HA>CAMP_REP_QST rep where eva.EVA_TYPE_REPONSE='N' 
and EVA_ID_CAMPAGNE=rep.ID_CAMP and eva.EVA_CODE_THEME=rep.ID_THEME and eva.EVA_ID_QUESTION=rep.ID_QUEST
<SEPARATEUR>
update eva set EVA_REPONSE=rep.REP_OUV
from <PREFIXE_DW>EVALUATIONS eva, <PREFIXE_HA>CAMP_REP_QST rep where eva.EVA_TYPE_REPONSE='O' 
and EVA_ID_CAMPAGNE=rep.ID_CAMP and eva.EVA_CODE_THEME=rep.ID_THEME and eva.EVA_ID_QUESTION=rep.ID_QUEST
<SEPARATEUR>
update eva set EVA_REPONSE=rep.REP_CALC
from <PREFIXE_DW>EVALUATIONS eva, <PREFIXE_HA>CAMP_REP_QST rep where eva.EVA_TYPE_REPONSE='C' 
and EVA_ID_CAMPAGNE=rep.ID_CAMP and eva.EVA_CODE_THEME=rep.ID_THEME and eva.EVA_ID_QUESTION=rep.ID_QUEST
<SEPARATEUR>
/*<VERSION_MINIMUM>10.31ae</VERSION_MINIMUM>*/
if  exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[EVA_THEMES]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table EVA_THEMES
select ID_CAMP as EVA_ID_CAMPAGNE,ID_THEME as EVA_CODE_THEME,LIB_THEME as EVA_LIBELLE_THEME,ID_PERE as EVA_ID_PERE,NM_ORDRE as EVA_NUMERO_ORDRE,
POIDS as EVA_POIDS,THEME_LIE as EVA_CODE_THEME_LIE
into EVA_THEMES
from <PREFIXE_HA>CAMP_QST_TH
<SEPARATEUR>
/*<VERSION_MINIMUM>10.31ae</VERSION_MINIMUM>*/
if  exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[EVA_NOTES_FINALES]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table EVA_NOTES_FINALES
select ID_CAMP as EVA_ID_CAMPAGNE,ID_THEME as EVA_CODE_THEME,CODE_FOU as EVA_CODE_FOURNISSEUR,ID_QUEST as EVA_ID_QUESTION,NOTE as EVA_NOTE_FINALE
into EVA_NOTES_FINALES
from <PREFIXE_HA>CAMP_NOT_FIN