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.
Author |
Topic |
akpaga
Constraint Violating Yak Guru
331 Posts |
Posted - 2014-02-13 : 15:35:06
|
Hi friends,I have a numeric column which when dispalyed in aresult set shows like thisCustomer_Score1.03.52.04.8 I want to show this in the following way13.524.8How can i achieve this thank you in advance. |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2014-02-13 : 16:54:25
|
Do the formatting in your application, not in SQL. This is a presentation layer issue and should not be handled in the database.Tara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
|
|
marcusn25
Yak Posting Veteran
56 Posts |
Posted - 2014-02-14 : 09:14:47
|
Not tested, hope this helps.case when Customer_Score like '%.0' THEN left(Customer_score,1) Else Customer_ScoreEnd as Customer_ScoreMarcus I learn something new everyday. |
|
|
ScottPletcher
Aged Yak Warrior
550 Posts |
Posted - 2014-02-14 : 17:47:10
|
[code]SELECT REPLACE(CAST(Customer_Score AS varchar(10)), '.0', '') AS Customer_ScoreFROM ( SELECT CAST(1.0 AS decimal(9, 1)) AS Customer_Score UNION ALL SELECT 3.5 UNION ALL SELECT 2.0 UNION ALL SELECT 4.8 ) AS test_data[/code] |
|
|
Vinnie881
Master Smack Fu Yak Hacker
1231 Posts |
Posted - 2014-02-17 : 00:12:25
|
You would be wiser to follow tkizer's advice, it is a much better practice. Success is 10% Intelligence, 70% Determination, and 22% Stupidity.\_/ _/ _/\_/ _/\_/ _/ _/- 881 |
|
|
mohan123
Constraint Violating Yak Guru
252 Posts |
Posted - 2014-02-20 : 08:22:30
|
this is the other way to do it DECLARE @tab Table (VAL VARCHAR(10))INSERT INTO @tab VALUES ('1.0')INSERT INTO @tab VALUES ('1.0')INSERT INTO @tab VALUES ('3.5')INSERT INTO @tab VALUES ('4.5')select CASE WHEN VAL LIKE '%.0%' THEN REPLACE(CAST(VAL AS DECIMAL(9,1)),'.0',' ') ELSE VAL END AS VAL from @tabP.V.P.MOhan |
|
|
|
|
|
|
|