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.

select (CAST(CAST(ColumnName AS float) AS INT))

or

select (CASE WHEN ISNUMERIC(ColumnName)=1 THEN CAST(CAST(ColumnName AS float) AS INT)END )

Illustration as
Create a table and insert values as:

create table payment(id varchar(5),amount nvarchar(15))
insert into payment values('E001',5000.00)

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

Using Syntax, write code as:

select (CAST(CAST(amount AS float) AS INT)) from Payment

Output for amount columns will be as int value:
amount
——-
5000

Advertisements

About Ravi Ranjan Kumar

An Indian who Living, Loving & Learning Technology with different tastes and willing to share knowledge and thoughts.
This entry was posted in SQL Server and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s