JetJack
JetJack

Reputation: 988

How to convert the float datatype to string

Using sql server 2000

Table1

id value (float)

001 10.00
002 
003 
004 08.50
...

i want to check the value column, if is null then display 'NA'

Tried Query

Select id,
CASE WHEN value  IS NULL then '-' else value end  AS value
from table1

'

Select id,
isnull(value, '-') AS value
from table1

Both query showing error as "Error converting data type varchar to float."

How to solve this issue.

need query help

Upvotes: 1

Views: 1863

Answers (4)

AnandPhadke
AnandPhadke

Reputation: 13486

select id,cast(isnull(value,'') as varchar(10)) from table

Upvotes: 0

mehdi lotfi
mehdi lotfi

Reputation: 11571

use below query :

SELECT id, ISNULL( CAST(value as VARCHAR(25)), 'NA')) as [Value]
FROM tableName

Upvotes: 0

John Woo
John Woo

Reputation: 263683

Try

SELECT id, CAST(COALESCE(value, 'NA') as VARCHAR(25)) as [Value]
FROM tableName

Upvotes: 1

podiluska
podiluska

Reputation: 51494

Select id, 
isnull(convert(varchar(20),value), '-') AS value 
from table1 

Upvotes: 3

Related Questions