Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
345 views
in Technique[技术] by (71.8m points)

sql - For XML length limitation

I am trying to concatenate results of some string data in a query using XML PATH

See query below.What happens is that the XML concatenated column statement gets truncated.Seems like there is a limitation on maximum length.How do I overcome this.

select SUBSTRING(statement,1,len(statement)-2)+';'
from(
select 
'update '+tab.table_name +' set ' +
(
select 
col.COLUMN_NAME +'=replace('+col.column_name+',''@xx'',''yy'') ,'+CHAR(10) 
from INFORMATION_SCHEMA.COLUMNS as col
where  tab.TABLE_CATALOG=col.TABLE_CATALOG
and tab.TABLE_SCHEMA=col.TABLE_SCHEMA
and tab.TABLE_NAME=col.TABLE_NAME
and col.DATA_TYPE in('VARCHAR','NVARCHAR')
for xml path('') )  as statement
from information_schema.TABLES as tab
) as x
where statement is not null
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Assuming you're seeing the truncation in SSMS, change your maximum character settings in SSMS's options:

  • Tools > Options > Query Results > SQL Server > Results to Text > Maximum number of characters displayed in each column

    (limit is 8192 characters)
    
  • Tools > Options > Query Results > SQL Server > Results to Grid > Maximum Characters Retrieved

    Non XML data limit is 65535 characters
    XML data limit is Unlimited
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...