moleskine di un programmatore

Appunti di viaggio tra bit e byte

Sql - Convertire un float in Euro (stringa)

Non ho trovato niente a riguardo (sicuramente esiste) quindi ho implementato questa piccola function che permette di convertire un valore float nella corrispondente rappresentazione monetaria letterale (Euro).

IF  EXISTS (SELECT * FROM sysobjects WHERE id = OBJECT_ID(N'[dbo].[PrxmKIFormatEuro]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
DROP FUNCTION [dbo].[PrxmKIFormatEuro]
go

create function PrxmKIFormatEuro(@value float)
returns varchar(30)
as
begin
    return replace(replace(replace(convert(varchar(30), convert(money,@value), 1),',','|'), '.', ','), '|','.') + ' €'
end
go

per usarla basta chiamarla nel seguente modo (ricordarsi di lasciare il dbo.)
select dbo.PrxmKIFormatEuro (1000.1)

Posted: Jun 18 2008, 01:45 PM by andrea.balducci | with no comments
Filed under: ,

Comments

No Comments