select
'07' as IDENTIFICADOR,
'300'||cast(scatcod as varchar) as codigo,
scatdes as descricao,
1 as ativo,
'100'||cast(deppcod as varchar) as codGrupoPai,
0 as ocultarNaLojaVirtual
from scat
join cat on scat.scatcatcod = catcod
join secp on cat.catsecpcod = secpcod
join depp on secp.secpdeppcod = deppcod 
where scatcod in (
select distinct(proscatcod) 
from pro 
join est on estprocod = procod and est.estdispb2b = 'S'
join uve on uveprocod = procod and uve.uvedispb2b = 'S'
where coalesce(proscatcod,0)>0
)
union 
select
'07' as IDENTIFICADOR,
'100'||cast(deppcod as varchar) as codigo,
deppdes as descricao,
1 as ativo,
'' as codGrupoPai,
0 as ocultarNaLojaVirtual
from scat
join cat on scat.scatcatcod = catcod
join secp on cat.catsecpcod = secpcod
join depp on secp.secpdeppcod = deppcod 
where scatcod in (
select distinct(proscatcod) 
from pro 
join est on estprocod = procod and est.estdispb2b = 'S'
join uve on uveprocod = procod --and uve.uvedispb2b = 'S'
where coalesce(proscatcod,0)>0
)
ExecutarScriptSempre
