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 + ']))'
WHERE TABLE_NAME = @TableName
SET @SQL = 'UPDATE [' + @TableName + '] SET ' + @SQL`enter code here`