In SQL Server 2014 Management Studio I have a query against a table, which contains the column "EntryNo" whose data type is FLOAT
.
I mention SQL Server 2014 Management Studio but the accepted answer should work with older versions. SQL Server 2008 R2 example .
Example:
Table: DocumentDetail
| EntryNo |
-----------
| 2435864 |
I need to return the value of the "EntryNo" column NVARCHAR(50)
without -for now- having to change the data type of table 1 .
I used " CAST (EntryNo AS NVARCHAR(50))
", but it returns this value:
2.43586e+006
And I need to return it like this:
2435864
How can I return the value correctly?
1 This column will later be modified to save alphanumeric values, but I haven't made this change yet = this change would affect the current operation.
You can add an
CAST
intermediate to an integer:Of course, this assumes that all values are actually integers, regardless of type
FLOAT
. But since you say that's your case, it should work fine.You can make use of the function
SRT
, where it receives as parameters the field to convert, the length and number of decimals. It is worth mentioning that this function is available from version 2008 of SQL Server.Here you can see the demo .