﻿/***************************************
* function f_genNewCodAL
*
* fornisce un nuovo cod AL a partire da 
* - codice origine completo
* - Tipo Assieme (nuovo)
* 
* es: ALR1401578A036 + "T" --> ALT1401578A036
*	T = cesta trattati
*
* Steamware, S.E.L.
* mod: 2014.03.14
*
****************************************/
create FUNCTION [dbo].[f_genNewCodAL]
(
	@SourceAL	NVARCHAR(50),
	@TipoAL		CHAR(1)
)
RETURNS NVARCHAR(50)
AS
	BEGIN
	
		DECLARE @answ AS NVARCHAR(50)
	
		SET @answ = 'AL'+ @TipoAL + SUBSTRING(@SourceAL, 4, LEN(@SourceAL) - 3)
	
	RETURN @answ
END