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
 General SQL Server Forums
 New to SQL Server Programming
 How to hide decimal places?

Author  Topic 

raysefo
Constraint Violating Yak Guru

260 Posts

Posted - 2010-09-29 : 03:17:29
Hi,

I m using MS SQL server 2008 and i have a table which has amount field (decimal (18,2)). What i would like to do is, hide decimal place if the amount is 5000.00

eg.

5000.00 -------> 5000
3000.45 -------> 3000.45

Best Regards

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2010-09-29 : 03:42:09
This is something you should do in your presentation level. It will be highly inefficient to do this in the database...

- Lumbago

My blog (yes, I have a blog now! just not that much content yet)
-> www.thefirstsql.com
Go to Top of Page

raysefo
Constraint Violating Yak Guru

260 Posts

Posted - 2010-09-29 : 04:06:08
I just want it when i use SELECT, i mean just for representing data NOT for modifying the original data!
I need something like below;

CONVERT(VARCHAR,CONVERT(DECIMAL,Amount),0) But this hides all decimal places...
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2010-09-29 : 04:25:26
I understand this but the fact that you want different handling based on the value will blow your performance. You could do something like this but it just doesn't make any sense:
DECLARE @table table (Amount decimal (18, 2))
INSERT INTO @table SELECT 5000 UNION ALL SELECT 3000.45

SELECT CASE
WHEN Amount - ROUND(Amount, 0) <> 0 THEN CAST(Amount as varchar(30))
ELSE CAST(CAST(Amount as decimal(18, 0)) as varchar(30))
END
FROM @table


- Lumbago

My blog (yes, I have a blog now! just not that much content yet)
-> www.thefirstsql.com
Go to Top of Page
   

- Advertisement -