SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Decimal Help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kabon
Starting Member

Indonesia
48 Posts

Posted - 03/11/2013 :  03:29:43  Show Profile  Reply with Quote
do you know how to display data like this

028.0000

can you help me for the script?

Luuk123
Yak Posting Veteran

52 Posts

Posted - 03/11/2013 :  03:53:08  Show Profile  Reply with Quote
You have to convert/cast it to a varchar. An integer/decimal etc. would remove the first 0.
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2224 Posts

Posted - 03/11/2013 :  05:47:26  Show Profile  Reply with Quote
see this example...

;WITH t(c) AS
(
SELECT 1.99 UNION ALL 
SELECT 21.34  UNION ALL 
SELECT 1797.94  UNION ALL 
SELECT -300.36  UNION ALL 
SELECT -21.99  UNION ALL 
SELECT -2.31 
) 
SELECT  
     CASE WHEN SIGN(c) = 1 THEN '' 
          ELSE '-' 
     END + REPLACE(STR(ABS(c), 7, 2), ' ','0') AS 'LeadingZerosWithSigns',
     REPLACE(STR(ABS(c), 7, 2), ' ','0') AS 'LeadingZerosWithOutSigns'
FROM t


--
Chandu
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 03/11/2013 :  06:36:33  Show Profile  Reply with Quote
how is your actual data existing in the table?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

kabon
Starting Member

Indonesia
48 Posts

Posted - 03/13/2013 :  00:17:50  Show Profile  Reply with Quote
for example like this :

select 2.00
Result : 2.00

select convert (numeric(20,4),2.00)
Result : 2.0000

how to make 002.0000
Go to Top of Page

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 03/13/2013 :  00:41:12  Show Profile  Reply with Quote
Without a specific reason, you should generally do that in the presentation layer rather than the database.
So why is it 002.0000 or 028.0000 and not 000000000000000002.0000 or 000028.0000 ?
What's your criteria?
Anyway, if you do think it has to be done in the database (and you should think twice) then bandi has already answered it for you.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000