Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
MSSQL NVARCHAR to INT conversions
--Sql Server 2014 Express Edition --Batches are separated by 'go' select @@version as 'sql server version'; -- variants with nvarchar to int conversion -- select origin nvarchar column type select convert(nvarchar(50),'2.54'); -- select directly converted float from origin nvarchar column type -- with dot as decimal separator select convert(float, convert(nvarchar(50),'2.54')); --cast float to int select cast (convert(float, convert(nvarchar(50),'2.54')) as int) ; --float to int by floor, cast to int select cast( floor (convert(float, convert(nvarchar(50),'2.54')) ) as int) ; --float to int by ceiling, cast to int select ceiling (convert(float, convert(nvarchar(50),'2.54')) ) ; --float to int rounded to x places select round (convert(float, convert(nvarchar(50),'2.54')),1 ) ; --float to int rounded to 0 places, cast to int select cast(round (convert(float, convert(nvarchar(50),'2.54')),0 ) as int) ; --possible use with nvarch column as data origin --select cast( floor (convert(float, MyNVARCHARColumn) ) as int) ; -- try variants with negative number!
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
a
Delete cascade
query
Digital Innovation One - SQL Server _2
sql to search database objects' definitions for text
String between two indexes
Microsoft SQL Server T-SQL in 10 minutes - products
Adding, subtracting, rounding and calculating differences
Practice
COMPUTED COLUMN
Please log in to post a comment.