简体   繁体   English

T-SQL-nvarchar的文本字段

[英]T-SQL - text field to nvarchar

I have a 'text' type in a SQL table (BigNote), and a new nvarchar(2000) field (LittleNote). 我在SQL表(BigNote)和新的nvarchar(2000)字段(LittleNote)中都有一个“文本”类型。

I need to save the first 2000 characters from the @BigNote into the LittleNote field within a stored procedure. 我需要将@BigNote中的前2000个字符保存到存储过程的LittleNote字段中。 Can someone share some thoughts? 有人可以分享一些想法吗?

Do I need to check for: - nulls? 我是否需要检查:-空值? - the BigNote length and only grab the exact amount? -BigNote的长度,只能抓取确切的数量吗?

It is working by just assigning LittleNote = @BigNote, but I want to avoid problems when the text is too big etc... 它只是通过分配LittleNote = @BigNote而起作用,但是我想避免在文本太大时出现问题等。

Once we release an update to the application, we will handle this more elegantly, but in the meantime we need to get a non-Text field with this data in the database. 一旦发布了对应用程序的更新,我们将更优雅地处理此问题,但是与此同时,我们需要在数据库中获取一个包含此数据的非Text字段。

you could use 你可以用

LittleNote = CONVERT(NVARCHAR(2000), @BigNote)

or with SUBSTRING 或使用SUBSTRING

LittleNote = SUBSTRING(@BigNote, 1, 2000)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM