Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Error converting data type nvarchar to bigint.

Author  Topic 

jjz
Starting Member

31 Posts

Posted - 2010-04-19 : 11:40:11
Good Day

I am trying to convert a nvarchar to bigint and getting this error msg:
Error converting data type nvarchar to bigint.

Below is the piece of code i've used:

select subnet,CAST(subnet as BIGINT)
from IP_Subnet_Table

The field (subnet) does not have null values

Please assist.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-19 : 11:43:17
make sure you dont have any non numeric data in column

try this first and see if it works

select subnet,CAST(subnet as BIGINT)
from IP_Subnet_Table
WHERE ISNUMERIC(subnet)=1


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-04-19 : 11:43:50
A fast shot:
cast(replace(subnet,'.','') as BIGINT)


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

jjz
Starting Member

31 Posts

Posted - 2010-04-19 : 11:45:36
This is the content of my field
10.84.82
10.85.32
10.85.33
10.85.34
10.85.35
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-19 : 11:46:34
quote:
Originally posted by jjz

This is the content of my field
10.84.82
10.85.32
10.85.33
10.85.34
10.85.35


how do you think you can convert this to bigint? the closest you can get is

select subnet,CAST(replace(subnet,'.','') as BIGINT)
from IP_Subnet_Table


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-04-19 : 11:46:37
Then my fast shot was right.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

jjz
Starting Member

31 Posts

Posted - 2010-04-19 : 11:49:16
thanx to both and yes Webfred your fast shot was spot on.

thax
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-04-19 : 11:50:08
welcome


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -