Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/68.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 将ntext转换为数字_Sql_Sql Server - Fatal编程技术网

Sql 将ntext转换为数字

Sql 将ntext转换为数字,sql,sql-server,Sql,Sql Server,我的一列被定义为ntextdatatype,许多流不再支持它。我正在尽最大努力将该列转换为数字或int,每次尝试都会达到任何目的 reg_no #my ntext field | name | country | etc | 我试图使用我们都使用的命令来更改col,但失败了 alter table tabl1 alter column [reg_no] numeric(38,0) 错误: 将数据类型nvarchar转换为数字时出错 关于修复此问题的任何建议,或者过去是否有人遇到过此问

我的一列被定义为
ntext
datatype,许多流不再支持它。我正在尽最大努力将该列转换为数字或int,每次尝试都会达到任何目的

reg_no #my ntext field | name | country | etc |
我试图使用我们都使用的命令来更改col,但失败了

alter table tabl1
    alter column [reg_no] numeric(38,0)
错误:

将数据类型nvarchar转换为数字时出错


关于修复此问题的任何建议,或者过去是否有人遇到过此问题,如果是,您是如何克服的

您应该能够通过两个步骤完成此操作:

alter table tabl1 alter column [reg_no] nvarchar(max);
alter table tabl1 alter column [reg_no] numeric(38,0);
ntext
已弃用,不支持转换为
numeric
,但支持转换为
nvarchar()

这假设这些值与
数值兼容。否则,将出现类型转换错误。如果发生这种情况,您可以使用以下方法获取有问题的值:

select *
from t
where try_convert(numeric(38, 0), try_convert(nvarchar(max), x)) is null
试试看

从表1中选择convert(int,convcert(varchar(40),reg_no))作为新字段名

你说的“失败”是什么意思?你收到错误消息了吗?那是什么?是否已检查列中所有现有值是否为数字?