I have a table with variables and values. The values column is in varchar(50). How can I cast the values, so they appear as they are in the column "Want"?
| Variable | Want | cast([Value] as varchar(50)) | cast(CAST([Value] AS float) as varchar(50)) |
| ------------ | ------------ | ------------ | ------------ |
| a | 77779999 | 7.778e+007 | 77779999 |
| b | -0.56 | -0.56 | -1 |
| c | 8.21 | 8.21 | 8 |
I'm using Microsoft SQL Server Management Studio.
EDIT:
My original data is as follows and I want to transpose it in one column with type varchar(50)
.
select 77779999 as var1, -0.56 as var2, 8.21 as var3
var1 (INT) | var2 (float) | var3 (float) |
---|---|---|
77779999 | -0.56 | 8.21 |
1条答案
按热度按时间ni65a41a1#
You can do something like this:
If the value is float, then it is cast to a FLOAT, otherwise not.
Another option is check for decimal point, this outputs varchar field.