Rabu, 14 April 2010
Format Currency di SQL Server
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER FUNCTION [dbo].[fn_format_currency] (@monetary_value decimal(20,0) ) returns varchar(20)
as
begin
declare @return_value varchar(20)
declare @is_negative bit
select @is_negative = case when @monetary_value<0 then 1 else 0 end
if @is_negative = 1
set @monetary_value = -1*@monetary_value
set @return_value = convert(varchar, isnull(@monetary_value, 0))
declare @before varchar(20), @after varchar(20)
if charindex ('.', @return_value )>0
begin
set @after= substring(@return_value, charindex ('.', @return_value ), len(@return_value))
set @before= substring(@return_value,1, charindex ('.', @return_value )-1)
end
else
begin
set @before = @return_value
set @after=''
end
-- after every third character:
declare @i int
if len(@before)>3
begin
set @i = 3
while @i>1 and @i < len(@before)
begin
set @before = substring(@before,1,len(@before)-@i) + ',' + right(@before,@i)
set @i = @i + 4
end
end
set @return_value = @before + @after
if @is_negative = 1
set @return_value = '-' + @return_value
return @return_value
end
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER FUNCTION [dbo].[fn_format_currency] (@monetary_value decimal(20,0) ) returns varchar(20)
as
begin
declare @return_value varchar(20)
declare @is_negative bit
select @is_negative = case when @monetary_value<0 then 1 else 0 end
if @is_negative = 1
set @monetary_value = -1*@monetary_value
set @return_value = convert(varchar, isnull(@monetary_value, 0))
declare @before varchar(20), @after varchar(20)
if charindex ('.', @return_value )>0
begin
set @after= substring(@return_value, charindex ('.', @return_value ), len(@return_value))
set @before= substring(@return_value,1, charindex ('.', @return_value )-1)
end
else
begin
set @before = @return_value
set @after=''
end
-- after every third character:
declare @i int
if len(@before)>3
begin
set @i = 3
while @i>1 and @i < len(@before)
begin
set @before = substring(@before,1,len(@before)-@i) + ',' + right(@before,@i)
set @i = @i + 4
end
end
set @return_value = @before + @after
if @is_negative = 1
set @return_value = '-' + @return_value
return @return_value
end
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
Langganan:
Posting Komentar (Atom)
Blog Archive
-
▼
2010
(24)
-
▼
April
(14)
- Me
- Ruh Seorang mukmin tergantung pada Hutangnya hingg...
- Banyak sekali pilihan web based wysiwg editor anta...
- Enkripsi di SQL Server
- Menghitung hari kerja di SQL Server
- Format Currency di SQL Server
- Admin Finder
- Ngakalin Registrasi di Visual Studio Express
- Detect invisible Yahoo! Messenger users
- Krapu CMS
- Hari ini, hari kedua gwe ngeblog di blogspot. Ise...
- Kajian Ilmiyyah Islamiyyah "Lau Kaana Khairan Lasa...
- My Program
- Download
-
▼
April
(14)
About Me
- Koral Web
- Kami adalah web developer. Beberapa produk yang pernah kami buat antara lain website, aplikasi klinik, aplikasi apotik, aplikasi EDMS (Electronic Database Management System), Energy Consumption Management System, RKBI (Rencana Kunjungan Barang Import) dan lain-lain sesuai dengan request dari client kami. Jika Anda tertarik untuk membuat system atau aplikasi, jangan sungkan-sungkan menghubungi kami.
Bahasa Pemrogramanmu?
Nasihat
Barangsiapa capek lelah dan letihnya bukan karena Allah maka celakalah dia
Diberdayakan oleh Blogger.
Web Sunnah
Blog Archieve
- Info (3)
- Kajian (3)
- My Program (1)
- Orang Terkenal (1)
- scrip (2)
- SQL (23)
- Subquery (9)
- Trik (13)
0 comments:
Posting Komentar