﻿CREATE function [C6MartPeriodico].[Codifica_CRisk_PhotoData]   
(
	@stringaCRisk_PhotoData as varchar(50)
)
RETURNS smallint
AS
BEGIN 
	declare @classeNum as smallint       
	SET @classeNum =
		CASE
			when (@stringaCRisk_PhotoData is null) then null
			when (@stringaCRisk_PhotoData = 'n.a.') then 0
			when (@stringaCRisk_PhotoData = 'Classe A') then 1
			when (@stringaCRisk_PhotoData = 'Classe B') then 2
			when (@stringaCRisk_PhotoData = 'Classe C') then 3
			when (@stringaCRisk_PhotoData = 'Classe D') then 4
			when (@stringaCRisk_PhotoData = 'Classe 1') then 1
			when (@stringaCRisk_PhotoData = 'Classe 2') then 2
			when (@stringaCRisk_PhotoData = 'Classe 3') then 3
			when (@stringaCRisk_PhotoData = 'Oltre<br>Classe 3') then 4
			when (@stringaCRisk_PhotoData = 'Oltre Classe 3') then 4
	end
	return @classeNum
END