[英]How to enter nvarchar data type in varcher datatype column in SQL Server?
I have two tables tb1
and tb2
. 我有两个表tb1
和tb2
。 tb1
has a column c1
of datatype varchar(15)
and tb2
which is created from an Excel file using import/export in SQL Server has a column c2
of datatype nvarchar(255)
. tb1
具有数据类型varchar(15)
的列c1
,并且使用SQL Server中的导入/导出从Excel文件创建的tb2
具有数据类型为nvarchar(255)
的列c2
。 All data is numeric with digits ranging from 5 to 12. I want to update the data in c1
with the values in c2
, but while updating through a query I am getting an error: 所有数据都是数字,数字范围从5到12.我想用c2
的值更新c1
的数据,但在通过查询更新时,我收到一个错误:
String or binary data would be truncated 字符串或二进制数据将被截断
How can I update data of c1
with the values of c2
? 如何使用c2
的值更新c1
数据?
The values in c2 probably have trailing spaces. c2中的值可能有尾随空格。 Use the trim function to remove the spaces. 使用trim函数删除空格。 Your update should be something like: 您的更新应该是这样的:
update tb1
set c1 = LTRIM(rtrim(tb2.c2))
from tb1
join tb2 on tb1.id=tb2.id
Your field is not big enough to hold your data. 您的字段不足以容纳您的数据。 you cant put something that can be 255 characters long into something that`s 15 characters long. 你不能把长度为255个字符的东西放到15个字符长的东西上。
You need to increase (c1) to at least varchar(255) 你需要将(c1)增加到至少varchar(255)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.