-- Schema: C6Mart
-- Stored Procedure: zzzQUALITY_CARATTERIVCONTRATTI

-- =============================================
-- 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

