1

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.

4

1 回答 1

2

如果存储的数据没有空格或其他非数字符号:

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

例如,如果有价值,(222)-3333-333它就会失败。如果值是2223333333它会成功

于 2013-10-31T13:51:05.010 回答