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
 Transact-SQL (2005)
 Convert varchar to numeric

Author  Topic 

KlausEngel
Yak Posting Veteran

85 Posts

Posted - 2010-07-19 : 21:29:02
I am trying to use CASE syntax to format the output of a numeric value to a string but I am receiving the error message:
[Error converting data type varchar to numeric.]

My query:
SELECT
names
, CASE WHEN numbers > 5 THEN '5 and more' ELSE numbers END
FROM MyTable

Any help is appreciated

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-07-19 : 21:59:53
you have to convert the numbers to string

CASE WHEN numbers > 5 THEN '5 and more' ELSE convert(varchar(10), numbers) END



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

KlausEngel
Yak Posting Veteran

85 Posts

Posted - 2010-07-19 : 22:03:31
Thank you!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-07-20 : 03:37:30
This is the formation issue that should be done in your front end application

Madhivanan

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

- Advertisement -