Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server Ms Sql将varchar转换为大整数_Sql Server_Varchar_Bigint - Fatal编程技术网

Sql server Ms Sql将varchar转换为大整数

Sql server Ms Sql将varchar转换为大整数,sql-server,varchar,bigint,Sql Server,Varchar,Bigint,我在下方的varchar中有客户电话号码值 客户电话号码值:(222)-3333-333 INSERT INTO DATABASE_1.dbo.CUSTOMER_TABLE ( Customer_Telephone_Number ) Select CONVERT(BIGINT,Customer_Telephone_Number) from DATABASE_2.DBO.CUSTOMER_TABLE 若ı尝试将Customer_Telephone_Number值插入数据库_1,我会得

我在下方的varchar中有客户电话号码值

客户电话号码值:(222)-3333-333

INSERT INTO DATABASE_1.dbo.CUSTOMER_TABLE 
(
Customer_Telephone_Number
)

Select

CONVERT(BIGINT,Customer_Telephone_Number)

from 
DATABASE_2.DBO.CUSTOMER_TABLE 
若ı尝试将Customer_Telephone_Number值插入数据库_1,我会得到以下异常

Error converting data type varchar to bigint.
那么我如何解决这个问题,或者我可以删除“(“and”)来解决问题呢?

任何帮助都将不胜感激


谢谢。

一个快速而肮脏的方法是:

Select
    CONVERT
    (
        BIGINT,
        REPLACE
        (
            REPLACE
            (
                REPLACE
                (
                    REPLACE
                    (
                        Customer_Telephone_Number,
                        ' ',--Replace white spaces
                        ''
                    ),
                    '-',--Replace dashes
                    ''
                ),
                '(',--Replace open parenthesis
                ''
            ),
            ')',--Replace close parenthesis
            ''
        )
     )
from 
    DATABASE_2.DBO.CUSTOMER_TABLE 
您可以运行以下操作以查看其他潜在字符:

select Customer_Telephone_Number 
from DATABASE_2.DBO.CUSTOMER_TABLE
where ISNUMERIC
    (
        REPLACE
        (
            REPLACE
            (
                REPLACE
                (
                    REPLACE
                    (
                        Customer_Telephone_Number,
                        ' ',--Replace white spaces
                        ''
                    ),
                    '-',--Replace dashes
                    ''
                ),
                '(',--Replace open parenthesis
                ''
            ),
            ')',--Replace close parenthesis
            ''
        )
    ) = 0

这将为您提供无法转换为
BIGINT
的电话号码列表。检查原因(例如,如果他们有一个
),并像我在示例中所做的那样将这些字符添加到替换中。

您知道哪些可能是非数字字符吗?1-()-222-2296 2-(332)-228-1180 3-()--