CREATE VIEW dbo.vCondizioniCapitoloAlternativa
AS
SELECT 15 AS IDCAPITOLO,RETE,COD_FISCALE,case COUNT(DISTINCT INTERMEDIARIO) WHEN 1 THEN 1 else 0 END AS CondValue
FROM	C6Mart.PATRIMONIO_TERZI
GROUP BY RETE,COD_FISCALE 
--union all
--select 17 AS IDCAPITOLO,'X' as RETE, 'XXXXXXXXXXXXXXXX'as COD_FISCALE,1 AS AS CondValue