Convert nvarchar, money and smallmoney datatype to int

This article enables you to convert nvarchar, money and smallmoney values to int. Simply, we can use the given conversion syntax to convert Nvarchar, smallmoney and money datatype values to int values.

[sourcecode language=”sql”] select (CAST(CAST(ColumnName AS float) AS INT))


[sourcecode language=”sql”] select (CASE WHEN ISNUMERIC(ColumnName)=1 THEN CAST(CAST(ColumnName AS float) AS INT)END )

Illustration as
Create a table and insert values as:

[sourcecode language=”sql”] create table payment(id varchar(5),amount nvarchar(15))
insert into payment values(‘E001’,5000.00)[/sourcecode]

after that out of “select * from payment” will be
id    amount 
—      ——-
E001   5000.00

Using Syntax, write code as:

[sourcecode language=”sql”] select (CAST(CAST(amount AS float) AS INT)) from Payment

Output for amount columns will be as int value:

Leave a Reply