Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Other SQL Server Topics (2005)
 formatting a field on SQL Server

Author  Topic 

whsbeernuts
Starting Member

11 Posts

Posted - 2007-09-11 : 13:17:42
Hello again,

I have a huge question haha. I just simply want to make a number display differently before I insert it into the table. for instance in Access, you can simply say FORMAT(c,format) ex: FORMAT(@CHARMINS, 00000) and it should work that way.

How would I accomplish this in SQL server? Right now I have the number 30 displaying as 30.00 in the variable it is set to.... I want it to be shown as 00030.... and any other number that is like 30.00, I want it shown the same way. Like 100.00 would be 00100. Thank you.

X002548
Not Just a Number

15586 Posts

Posted - 2007-09-11 : 13:36:09
It doesn't store it in the database that way, it just displays it

If you want to store it that way, it needs to be char, nchar, varchar, or nvarchar



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

whsbeernuts
Starting Member

11 Posts

Posted - 2007-09-11 : 13:39:02
Yes it is a char that is being stored! When it displays 00030... that's a char. I need to convert the 30.00 from numeric(19,2) to a char(7) and also display it as a char(7) with this format: 00000

There is some more information for you. Thanks
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-09-11 : 13:45:39
[code]
DECLARE @x decimal(19,2), @y char(7)
SET @x = 30.00

SELECT @y = RIGHT(REPLICATE('0',7)+CONVERT(varchar(7),CONVERT(int,@x)),7)

SELECT @x, @y

[/code]

Not that this makes any sense



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-09-12 : 02:06:50
As usual, if you want to show formatted data at front end, you can use format function there

VB6 ex

Format(Rs("Decimal_column"),"0000000")

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -