September 24, 2013 at 11:23 am
How to trim a large table with more than 300 columns dynamically. when i tried with this code i was getting an error because the variable @sql is of nvarchar(max) and i have like 300 columns so all the column names were not coming when i run this query can any of the guys help me in this ?
DECLARE @SQL nVARCHAR(MAX)
DECLARE @TableName NVARCHAR(128)
SET @TableName = 'MYTAbleName'
SELECT @SQL = COALESCE(@SQL + ',[', '[') +
COLUMN_NAME + ']=LTRIM(RTRIM([' + COLUMN_NAME + ']))'
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = @TableName
SET @SQL = 'UPDATE [' + @TableName + '] SET ' + @SQL`enter code here`
PRINT @SQL
EXECUTE @SQL
September 24, 2013 at 12:07 pm
NOTE: Cross-posted at Stackoverflow: http://stackoverflow.com/questions/18988246/trimming-empty-spaces-in-large-table-sql-serever
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply