Files
GMW/GMW_DB/dbo/Functions/getUdcComp.sql
T
Samuele Locatelli a6d7ea0b2f Import iniziale DB, GMW
versione TK 2.4
inclusione schema voc x tabella lingue e vocabolario
2014-02-20 09:54:57 +01:00

34 lines
789 B
Transact-SQL

/***************************************
* function getUdcComp
*
* effettua la "compattazione" dell'UDC, andando a prendere un sottoinsieme dei dati iniziali (UAAxxxx dove AA = anno...)
*
* Steamware, S.E.L.
* mod: 2010.09.23
*
****************************************/
CREATE FUNCTION [dbo].[getUdcComp]
(
@fullUDC NVARCHAR(50),
@maxLen INTEGER
)
RETURNS NVARCHAR(20)
AS
BEGIN
-- calcolo lunghezza originale
DECLARE @fullLen AS INT
SET @fullLen = LEN(LTRIM(RTRIM(@fullUDC)))
-- dichiaro stringa out (max 20 char)
DECLARE @answ NVARCHAR(20)
-- recupero parte finale (ultimi @maxLen caratteri...)
-- compongo codice
SET @answ = 'U' + RIGHT(LEFT(@fullUDC, 7), 2) + RIGHT(LTRIM(RTRIM(@fullUDC)),@maxLen-3) -- tolgo 3 char: U + anno...
RETURN @answ
END