-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date, ,>
-- Description:	<Description, ,>
-- =============================================
CREATE FUNCTION [C6Mart].[getAppellativo]
(
	-- Add the parameters for the function here
	@Sesso varchar(1),
	@Cod_fiscale varchar(16)
)
RETURNS VARCHAR(150)
AS
BEGIN
	-- Declare the return variable here
	DECLARE @Appellativo VARCHAR(150)
	IF(LEN(@Cod_fiscale) = 16 AND CHARINDEX('@',@Cod_fiscale) = 0)
		BEGIN
			IF(@Sesso = 'F')
				--SET @Appellativo = 'Gent. Sig.ra'
				SET @Appellativo = 'Gentile signora'
			ELSE
				--SET @Appellativo = 'Egr. Sig.'
				SET @Appellativo = 'Gentile signore'
		END
	ELSE
	--SET @Appellativo = 'Spett.le' 
    SET @Appellativo = 'Spettabile'
	-- Return the result of the function
	RETURN @Appellativo
END