Format Money To User Interface

7 06 2007

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
CREATE FUNCTION dbo.FormatMoneyToUI( @format as numeric(16,2) )
RETURNS VARCHAR(255)
AS
BEGIN
DECLARE @dtVC VARCHAR(255)
SELECT @dtVC = rtrim(convert(varchar,cast(@format as money), 1))

RETURN @dtVC
END
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

ini gw pake buat nampilin data duit di dataGrid, ato langsung diambil nilainya jika diperlukan. Soalnya klo di dataGrid ada DataFormatString=”{0:#,0.0}”, nah klo permasalahannya nilainya langsung diambil gimana? hehe.. pake aja cara diatas ntu…..

note: input pernah gw coba pake dataType: Double tp ternyata ga bisa dikompile.





jumlah row tiap tabel dalam database.

28 05 2007

Hi.. aq dapet ni source dari internet. please use it, mungkin berguna buat temen2 sekalian..

_____________________________________________________
print '--delete the final UNION before the ORDER BY'
print '--  before running this script.'
print '--'
goexec sp_msforeachtable @command1="print 'SELECT ''?'' AS TableName,
	COUNT(*) as TblRowCount FROM ?' print 'UNION'"
go
print 'ORDER BY TableName'
go
______________________________________________________

 

I wrote this code to make it easier to compare record counts between a live database and a restored copy to test my backups, I thought people might find it useful. You need to run it against your live side when you do the backup that you’re going to restore and compare against.

Copy the output into another Query Analyzer window and run it: instant record counts.

Suck the results into Excel, run the script again against the restored DB, and you should be able to see any problems fairly quickly. I would expect perhaps a minor variation in counts, this should at least show you any radical changes.

I’ve only tested this under SQL Server 2000 SP3a.

note: aq dah nyobain ini di SqlServer2000 SP4.





format tanggal

24 04 2007

Sering kali suatu aplikasi database client server berhadapan dengan format tanggal, musti pake format client, server ato database? iya kalo2 format tanggal sama [dalam artian sesuai dengan dlm database n UserInterface] nah klo nggak? ampunwaaa… bisa stresss. Disini gw mo nambahin storedProcedure buat dapetin format [lebih dari 1 seeh... ]

ni dia scriptna:mikir

CREATE FUNCTION dbo.FormatDateTime(  @dt DATETIME,

@format VARCHAR(16)

)RETURNS VARCHAR(64)

ASBEGIN

DECLARE @dtVC VARCHAR(64)

SELECT @dtVC = CASE @format

WHEN 'LONGDATE' THEN

DATENAME(dw, @dt) + ',' + SPACE(1) + DATENAME(m, @dt)

+ SPACE(1) + CAST(DAY(@dt) AS VARCHAR(2))

+ ',' + SPACE(1) + CAST(YEAR(@dt) AS CHAR(4))

WHEN 'LONGDATEANDTIME' THEN	DATENAME(dw, @dt)

+ ',' + SPACE(1) + DATENAME(m, @dt)	+ SPACE(1) + CAST(DAY(@dt) AS VARCHAR(2))

+ ',' + SPACE(1) + CAST(YEAR(@dt) AS CHAR(4))	+ SPACE(1)    + RIGHT(CONVERT(CHAR(20),

@dt - CONVERT(DATETIME, CONVERT(CHAR(8),

@dt, 112)), 22), 11)

WHEN 'SHORTDATE' THEN

LEFT(CONVERT(CHAR(19), @dt, 0), 11)

WHEN 'SHORTDATEANDTIME' THEN

REPLACE(REPLACE(CONVERT(CHAR(19), @dt, 0),

'AM', ' AM'), 'PM', ' PM')

WHEN 'UNIXTIMESTAMP' THEN

CAST(DATEDIFF(SECOND, '19700101', @dt) AS VARCHAR(64))

WHEN 'YYYYMMDD' THEN

CONVERT(CHAR(8), @dt, 112)

WHEN 'YYYY-MM-DD' THEN

CONVERT(CHAR(10), @dt, 23)

WHEN 'YYMMDD' THEN

CONVERT(VARCHAR(8), @dt, 12)

WHEN 'YY-MM-DD' THEN

STUFF(STUFF(CONVERT(VARCHAR(8), @dt, 12),

5, 0, '-'), 3, 0, '-')

WHEN 'MMDDYY' THEN

REPLACE(CONVERT(CHAR(8), @dt, 10), '-', SPACE(0))

WHEN 'MM-DD-YY' THEN

CONVERT(CHAR(8), @dt, 10)

WHEN 'MM/DD/YY' THEN

CONVERT(CHAR(8), @dt, 1)

WHEN 'MM/DD/YYYY' THEN

CONVERT(CHAR(10), @dt, 101)

WHEN 'DDMMYY' THEN

REPLACE(CONVERT(CHAR(8), @dt, 3), '/', SPACE(0))

WHEN 'DD-MM-YY' THEN

REPLACE(CONVERT(CHAR(8), @dt, 3), '/', '-')

WHEN 'DD/MM/YY' THEN

CONVERT(CHAR(8), @dt, 3)

WHEN 'DD/MM/YYYY' THEN

CONVERT(CHAR(10), @dt, 103)

WHEN 'HH:MM:SS 24' THEN

CONVERT(CHAR(8), @dt, 8) 

WHEN 'HH:MM 24' THEN

LEFT(CONVERT(VARCHAR(8), @dt, 8), 5)

WHEN 'HH:MM:SS 12' THEN

LTRIM(RIGHT(CONVERT(VARCHAR(20), @dt, 22), 11))

WHEN 'HH:MM 12' THEN

LTRIM(SUBSTRING(CONVERT(

VARCHAR(20), @dt, 22), 10, 5)

+ RIGHT(CONVERT(VARCHAR(20), @dt, 22), 3))

ELSE

'Invalid format specified'

END

RETURN @dtVC

END

nah klo pake ini kan lebih enak, you tinggal pake n masukin format.
like this:

 

EXEC dbo.FormatDateTime(getdate(), 'DD/MM/YYYY')

sekarang, kenapa ini dikatakan lebih baik?
1. tanggal yang diambil sesuai dengan tanggal yang ada dalam database, it means we are not using local date neither local server date, but database date. Ini yang akan memaintain sinkronisasi antara tanggal client server.
2. “getdate()” dapat diganti dengan tanggal dari inputan user.

sctript ini gw dapet dari internet, gw lupa ngambilnya dimana… th_013 anyway, thanks buat yang dah bikin script ini.. :P