简体   繁体   中英

SELECT values from ntext column are truncated

I have table which consists column of ntext data type.

I write query that search for some example, like:

SELECT 
    Id,
    NtextColumnName
FROM Table
WHERE 
    NtextColumnName LIKE N'%search_term%'

and got certain number of rows. but, when viewing this column to find this search_term I don't see it, it seems that result is truncated.

I also tried to show result in text and apply Find, but no result.

How can I examine existence of some search term in NtextColumnName column, and also make this result visible?

Depending on how long your column data is, if you're just looking to view the data in Management Studio, cast the column to an XML data type:

declare @t1 table(c1 ntext)
insert into @t1 values(space(5000) + 'a' + space(5000))
select cast(c1 as xml) from @t1

That example will give you a single column, which you can click on to see the entire set of data in a new window.

The settings for maximum amount of data returned:

  • Tools | Options | Query Results | SQL Server | Results to Text | Maximum number of characters displayed in each column
  • Tools | Options | Query Results | SQL Server | Results to Grid | Maximum Characters Retrieved

Edit: to get the full value, for larger data sizes, this answer points to the correct way to wrap it in a CDATA column:

declare @t1 table(c1 ntext)
insert into @t1 values(space(10000) + 'a' + space(10000))
select 
  convert(xml,'<xml><![CDATA[' + cast(c1 as varchar(max)) + ']]></xml>') 
from 
  @t1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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