简体   繁体   English

如何在SQL Server的varcher数据类型列中输入nvarchar数据类型?

[英]How to enter nvarchar data type in varcher datatype column in SQL Server?

I have two tables tb1 and tb2 . 我有两个表tb1tb2 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.

相关问题 SQL Server中具有XML数据的nvarchar数据类型的索引 - Index on nvarchar datatype with XML data in SQL Server 如果要索引的列是SQL Server中的nvarchar数据类型,该怎么办? - What if the column to be indexed is nvarchar data type in SQL Server? SQL Server:将列数据类型从datetime2更改为nvarchar,同时转换现有数据 - SQL Server: change column datatype from datetime2 to nvarchar, convert existing data simultaneously Select xml 来自 SQL 服务器中 nvarchar 数据类型列的标签 - Select xml tags from nvarchar datatype column in SQL Server 当列在 Microsoft SQL Server 中为 nvarchar 类型时如何按日期排序 - How to order by date when a column is of type nvarchar in Microsoft SQL Server 如何在 SQL Server 中更改列数据类型并转换以前的类型而不丢失数据 - How to change column datatype in SQL Server and convert previous type without losing data 如何将 nvarchar 转换为 SQL 服务器的 int 类型 - How to convert nvarchar into int type for SQL Server SQL将列数据类型从nvarchar更改为int - SQL alter column datatype from nvarchar to int SQL Server日期数据类型变为nvarchar - SQL Server date datatype becomes nvarchar 如何在SQL Server 2008中将所有varchar数据类型列更改为Nvarchar数据类型列 - How to change all varchar datatype columns to Nvarchar datatype columns in sql server 2008
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM