-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE procedure [C6Mart].[zzzQUALITY_CARATTERIVCONTRATTI]
AS
BEGIN
declare @num int 
set @num = 1
CREATE TABLE #tab_temp(
	[Val_Ascii] [smallint] NOT NULL,
	[Val_Char] [varchar](1) NOT NULL,
	[Rete] [varchar](1) NOT NULL,
	[Cod_Fiscale] [varchar](16) NOT NULL,
	[Nome_Campo] [varchar](50) NOT NULL,
	[Val_Campo] [varchar](150) NOT NULL)
set @num = 1
while @num < 150
begin	
	insert into #tab_temp
	SELECT ascii(substring(email,@num,1)),
		   substring(email,@num,1),
		   rete,
		   Cod_Fiscale,
		   'EMAIL',
		   email
	FROM C6Mart.vcontratti
	WHERE 
		ascii(substring(email,@num,len(email))) not between 64 and 90 
		and ascii(substring(email,@num,len(email))) not between 97 and 122
		and ascii(substring(email,@num,len(email))) not between 48 and 57
		and ascii(substring(email,@num,len(email))) <> 32
		and ascii(substring(email,@num,len(email))) <> 40
		and ascii(substring(email,@num,len(email))) <> 41
		and ascii(substring(email,@num,len(email))) <> 43
		and ascii(substring(email,@num,len(email))) <> 44
		and ascii(substring(email,@num,len(email))) <> 45
		and ascii(substring(email,@num,len(email))) <> 46
		and ascii(substring(email,@num,len(email))) <> 95
		and ascii(substring(email,@num,len(email))) <> 39
		and ascii(substring(email,@num,len(email))) <> 47
		and ascii(substring(email,@num,len(email))) <> 63
	set @num = @num + 1	
end	
set @num = 1
while @num < 150
begin	
		insert into #tab_temp
		SELECT ascii(substring(Indirizzo,@num,1)),
			   substring(Indirizzo,@num,1),
			   rete,
			   Cod_Fiscale,
			   'INDIRIZZO',
			   Indirizzo
		FROM C6Mart.vcontratti
		WHERE 
			ascii(substring(Indirizzo,@num,len(Indirizzo))) not between 64 and 90 
		and ascii(substring(Indirizzo,@num,len(Indirizzo))) not between 97 and 122
		and ascii(substring(Indirizzo,@num,len(Indirizzo))) not between 48 and 57
		and ascii(substring(Indirizzo,@num,len(Indirizzo))) <> 32
		and ascii(substring(Indirizzo,@num,len(Indirizzo))) <> 40
		and ascii(substring(Indirizzo,@num,len(Indirizzo))) <> 41
		and ascii(substring(Indirizzo,@num,len(Indirizzo))) <> 43
		and ascii(substring(Indirizzo,@num,len(Indirizzo))) <> 44
		and ascii(substring(Indirizzo,@num,len(Indirizzo))) <> 45
		and ascii(substring(Indirizzo,@num,len(Indirizzo))) <> 46
		and ascii(substring(Indirizzo,@num,len(Indirizzo))) <> 95
		and ascii(substring(Indirizzo,@num,len(Indirizzo))) <> 39
		and ascii(substring(Indirizzo,@num,len(Indirizzo))) <> 47
		and ascii(substring(Indirizzo,@num,len(Indirizzo))) <> 63
		set @num = @num + 1		
end	
set @num = 1
while @num < 150
begin	
		insert into #tab_temp
		SELECT ascii(substring(CAP,@num,1)),
			   substring(CAP,@num,1),
			   rete,
			   Cod_Fiscale,
			   'CAP',
			   CAP
		FROM C6Mart.vcontratti
		WHERE 
			ascii(substring(CAP,@num,len(CAP))) not between 64 and 90 
		and ascii(substring(CAP,@num,len(CAP))) not between 97 and 122
		and ascii(substring(CAP,@num,len(CAP))) not between 48 and 57
		and ascii(substring(CAP,@num,len(CAP))) <> 32
		and ascii(substring(CAP,@num,len(CAP))) <> 40
		and ascii(substring(CAP,@num,len(CAP))) <> 41
		and ascii(substring(CAP,@num,len(CAP))) <> 43
		and ascii(substring(CAP,@num,len(CAP))) <> 44
		and ascii(substring(CAP,@num,len(CAP))) <> 45
		and ascii(substring(CAP,@num,len(CAP))) <> 46
		and ascii(substring(CAP,@num,len(CAP))) <> 95
		and ascii(substring(CAP,@num,len(CAP))) <> 39
		and ascii(substring(CAP,@num,len(CAP))) <> 47
		and ascii(substring(CAP,@num,len(CAP))) <> 63
		set @num = @num + 1		
end	
set @num = 1
while @num < 150
begin	
		insert into #tab_temp
		SELECT ascii(substring(Citta,@num,1)),
			   substring(Citta,@num,1),
			   rete,
			   Cod_Fiscale,
			   'Citta',
			   Citta
		FROM C6Mart.vcontratti
		WHERE 
			ascii(substring(Citta,@num,len(Citta))) not between 64 and 90 
		and ascii(substring(Citta,@num,len(Citta))) not between 97 and 122
		and ascii(substring(Citta,@num,len(Citta))) not between 48 and 57
		and ascii(substring(Citta,@num,len(Citta))) <> 32
		and ascii(substring(Citta,@num,len(Citta))) <> 40
		and ascii(substring(Citta,@num,len(Citta))) <> 41
		and ascii(substring(Citta,@num,len(Citta))) <> 43
		and ascii(substring(Citta,@num,len(Citta))) <> 44
		and ascii(substring(Citta,@num,len(Citta))) <> 45
		and ascii(substring(Citta,@num,len(Citta))) <> 46
		and ascii(substring(Citta,@num,len(Citta))) <> 95
		and ascii(substring(Citta,@num,len(Citta))) <> 39
		and ascii(substring(Citta,@num,len(Citta))) <> 47
		and ascii(substring(Citta,@num,len(Citta))) <> 63
		set @num = @num + 1		
end	
set @num = 1
while @num < 150
begin	
insert into #tab_temp
SELECT ascii(substring(Provincia,@num,1)),
       substring(Citta,@num,1),
       rete,
       Cod_Fiscale,
       'Provincia',
       Provincia
FROM C6Mart.vcontratti
WHERE 
	ascii(substring(Provincia,@num,len(Provincia))) not between 64 and 90 
and ascii(substring(Provincia,@num,len(Provincia))) not between 97 and 122
and ascii(substring(Provincia,@num,len(Provincia))) not between 48 and 57
and ascii(substring(Provincia,@num,len(Provincia))) <> 32
and ascii(substring(Provincia,@num,len(Provincia))) <> 40
and ascii(substring(Provincia,@num,len(Provincia))) <> 41
and ascii(substring(Provincia,@num,len(Provincia))) <> 43
and ascii(substring(Provincia,@num,len(Provincia))) <> 44
and ascii(substring(Provincia,@num,len(Provincia))) <> 45
and ascii(substring(Provincia,@num,len(Provincia))) <> 46
and ascii(substring(Provincia,@num,len(Provincia))) <> 95
and ascii(substring(Provincia,@num,len(Provincia))) <> 39
and ascii(substring(Provincia,@num,len(Provincia))) <> 47
and ascii(substring(Provincia,@num,len(Provincia))) <> 63
set @num = @num + 1	
end	
set @num = 1
while @num < 150
begin	
insert into #tab_temp
SELECT ascii(substring(Nazione,@num,1)),
       substring(Nazione,@num,1),
       rete,
       Cod_Fiscale,
       'Nazione',
       Nazione
FROM C6Mart.vcontratti
WHERE 
	ascii(substring(Nazione,@num,len(Nazione))) not between 64 and 90 
and ascii(substring(Nazione,@num,len(Nazione))) not between 97 and 122
and ascii(substring(Nazione,@num,len(Nazione))) not between 48 and 57
and ascii(substring(Nazione,@num,len(Nazione))) <> 32
and ascii(substring(Nazione,@num,len(Nazione))) <> 40
and ascii(substring(Nazione,@num,len(Nazione))) <> 41
and ascii(substring(Nazione,@num,len(Nazione))) <> 43
and ascii(substring(Nazione,@num,len(Nazione))) <> 44
and ascii(substring(Nazione,@num,len(Nazione))) <> 45
and ascii(substring(Nazione,@num,len(Nazione))) <> 46
and ascii(substring(Nazione,@num,len(Nazione))) <> 95
and ascii(substring(Nazione,@num,len(Nazione))) <> 39
and ascii(substring(Nazione,@num,len(Nazione))) <> 47
and ascii(substring(Nazione,@num,len(Nazione))) <> 63
set @num = @num + 1	
end	
set @num = 1
while @num < 150
begin	
insert into #tab_temp
SELECT ascii(substring(Presso,@num,1)),
       substring(Presso,@num,1),
       rete,
       Cod_Fiscale,
       'Presso',
       Presso
FROM C6Mart.vcontratti
WHERE 
	ascii(substring(Presso,@num,len(Presso))) not between 64 and 90 
and ascii(substring(Presso,@num,len(Presso))) not between 97 and 122
and ascii(substring(Presso,@num,len(Presso))) not between 48 and 57
and ascii(substring(Presso,@num,len(Presso))) <> 32
and ascii(substring(Presso,@num,len(Presso))) <> 40
and ascii(substring(Presso,@num,len(Presso))) <> 41
and ascii(substring(Presso,@num,len(Presso))) <> 43
and ascii(substring(Presso,@num,len(Presso))) <> 44
and ascii(substring(Presso,@num,len(Presso))) <> 45
and ascii(substring(Presso,@num,len(Presso))) <> 46
and ascii(substring(Presso,@num,len(Presso))) <> 95
and ascii(substring(Presso,@num,len(Presso))) <> 39
and ascii(substring(Presso,@num,len(Presso))) <> 47
and ascii(substring(Presso,@num,len(Presso))) <> 63
set @num = @num + 1	
end	
 select * from #tab_temp a
--inner join c6mart.gestione_pdf_ftp b on a.rete=b.rete and a.cod_fiscale=b.codicefiscale 
--where flaginvio = 'N'
END