Bharat Guru
asked on
How to convert decimal to varchar
Select OrderID,
'Sell--' + Convert(varchar(24), sum(CAST(Price AS DECIMAL(13,2))) )
From OrderDetail
GroupBy OrderID
I want to display price as varchar but somehow above code send an following error
"Error converting data type varchar to numeric."
I want to display result as following
OrderID Price
-----------------
1, S-212.23
2, S-46.83
3, S-912.20
4, S-52.73
'Sell--' + Convert(varchar(24), sum(CAST(Price AS DECIMAL(13,2))) )
From OrderDetail
GroupBy OrderID
I want to display price as varchar but somehow above code send an following error
"Error converting data type varchar to numeric."
I want to display result as following
OrderID Price
-----------------
1, S-212.23
2, S-46.83
3, S-912.20
4, S-52.73
ASKER
I actually want to do something like following
Declare @Temp CHAR (1)
Set @Temp = 'Y'
Select OrderID,
Case When @Temp = 'Y' Then
Convert(varchar(24), sum(CAST(Price AS DECIMAL(13,2))) )
Else
sum(CAST(Price AS DECIMAL(13,2)))
End AS "Price"
From OrderDetail
GroupBy OrderID
Price is a varchar field in table
Declare @Temp CHAR (1)
Set @Temp = 'Y'
Select OrderID,
Case When @Temp = 'Y' Then
Convert(varchar(24), sum(CAST(Price AS DECIMAL(13,2))) )
Else
sum(CAST(Price AS DECIMAL(13,2)))
End AS "Price"
From OrderDetail
GroupBy OrderID
Price is a varchar field in table
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
sounds like you've got some invalid data... what is the datatype of the price column?
Select OrderID,
'Sell--' +Convert(varchar(24),sum(c
else 0.00 end))
From OrderDetail
GroupBy OrderID
and use this to identify any non numerics..
select orderid , price
from orderdetail
where isnumeric(price) = 0