Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
MSSQL NVARCHAR to INT conversions
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
--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!
View schema
Execution time: 0 sec, rows selected: 8, rows affected: 0, absolute service time: 0,16 sec
edit mode
|
history
|
discussion
sql server version
1
Microsoft SQL Server 2014 - 12.0.2000.8 (Intel X86) Feb 20 2014 19:20:46 Copyright (c) Microsoft Corporation Express Edition on Windows NT 6.3 <X64> (Build 9600: ) (WOW64) (Hypervisor)
(No column name)
1
2.54
(No column name)
1
2,54
(No column name)
1
2
(No column name)
1
2
(No column name)
1
3
(No column name)
1
2,5
(No column name)
1
3