Question

I have two databases.I insert data from DATABASE_2 TO DATABASE_1 however i need to convert some column.

I must convert Customer_Telephone_Number from varchar to bigint after that insert it.

So,

My Question is in below.

SET IDENTITY_INSERT DATABASE_1.dbo.CUSTOMER_TABLE ON

INSERT INTO DATABASE_1.dbo.CUSTOMER_TABLE 
(
Customer_Id,
Customer_Telephone_Number
)
Select

Customer_Id,
Customer_Telephone_Number // This is varchar so i need to convert it to Big int.

from 
DATABASE_2.DBO.CUSTOMER_TABLE 

Any help will be appreciated.

Thanks.

Was it helpful?

Solution

If the data stored is without spaces or other non numeric symbols:

Select
    Customer_Id,
    CONVERT(BIGINT,Customer_Telephone_Number)    
from 
    DATABASE_2.DBO.CUSTOMER_TABLE 

For instance, if there is value with (222)-3333-333 it would fail. If the value was 2223333333 it would succeed

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top