sql server - trimming empty spaces in large table sql serever -


how trim large table more 300 columns dynamically. when tried code getting error because variable @sql of nvarchar(max) , have 300 columns column names not coming when run query can of guys me in ?

    declare @sql nvarchar(max)     declare @tablename nvarchar(128)     set @tablename = 'mytablename'      select @sql = coalesce(@sql + ',[', '[') +      column_name + ']=ltrim(rtrim([' + column_name + ']))'     information_schema.columns     table_name = @tablename        set @sql = 'update [' + @tablename + '] set ' + @sql       print @sql       execute @sql 

while have defined @sql nvarchar(max), boils down how query sent sql server engine.

quote msdn maximum capacity specifications.

"network packet size size of tabular data stream (tds) packets used communicate between applications , relational database engine. default packet size 4 kb, , controlled network packet size configuration option."

the max batch size 64 * 4 or 250 mb query submitted engine. alot smaller (max) = 2gb.

add debugging line see if coming close limitation. comment out printing t-sql , executing query.

-- show how long dynamic t-sql -- print @sql print 'len of tsql' print len(@sql) -- execute @sql 

please report if issue!

i not have test case yours.

-- use msdb use msdb go  -- largest column count = 62, [sysutility_ucp_instances] select table_name, max(ordinal_position) maxcols information_schema.columns group table_name  order max(ordinal_position) desc 

since tsql getting cut off, must casting varchar() has max of 8000 bytes.

try casting each piece of update varchar(max).

set @sql = cast('update [' varchar(max)) + cast(@tablename varchar(max)) + cast('] set ' varchar(max)) + @sql; 

use varchar() instead of nvarchar 1 power of 2 back.

i hope fixes issue.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

c++ - Clear the memory after returning a vector in a function -

erlang - Saving a digraph to mnesia is hindered because of its side-effects -