Created
December 11, 2014 20:46
-
-
Save anonymous/f02941a1d04a1969fc62 to your computer and use it in GitHub Desktop.
Dynamic SQL replace all columns
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare @column varchar(max) | |
declare @sql nvarchar(max) | |
declare @tablename varchar(max) | |
declare tables cursor for select column_name from INFORMATION_SCHEMA.columns where table_name ='Salesforce_Task_Backup_12102014' and column_name!='ID' | |
Open tables | |
Fetch Next FROM tables | |
into @column | |
--set @column='userguid' | |
--set @value='5000010431119001' | |
While @@Fetch_Status = 0 | |
Begin | |
set @sql=N'update Salesforce_Task_Backup_12102014 set '+ @column+' = substring('+@column+',1,len('+@column+')-1)' | |
--set @sql=N'update Salesforce_Task_Backup_12102014 set '+ @column+ ' = right('+@column+',2,len('+@column+')' | |
-- print @sql | |
exec sp_executesql @sql | |
fetch NEXT FROM tables | |
Into @column | |
End | |
Close tables | |
deallocate tables | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment