--[CERCA] '%COD%','P','c6martperiodico'
CREATE procedure  [dbo].[vinfocliente]
   @cf VARCHAR(16)
AS
BEGIN
 SELECT *
    FROM consuni.consulenzaunica.dbo.vinfocliente
    WHERE codfis = @cf or piva=@cf or codman=SUBSTRING(@cf,4,len(@cf)) or codicecontratto=@cf
 SELECT chiaveclientepb,codicecontratto
	into #chpb
    FROM consuni.consulenzaunica.dbo.vinfocliente
    WHERE codfis = @cf or piva=@cf or codman=SUBSTRING(@cf,4,len(@cf)) or codicecontratto=@cf
select * from consuni.consulenzaunica.dbo.contratto where chiaveclientepb in (SELECT chiaveclientepb
	from #chpb)
 SELECT *
    FROM consuni.consulenzaunicafl.dbo.cbs_histdatiingresso where trcom_codconf in (SELECT codicecontratto
	from #chpb) order by 1 desc
END