sql Ioop requirement for running below query -


i using below query;

enter code here  use hn_backup set nocount on   declare @stringtofind varchar(100)  declare @stringtoreplace varchar(100)  declare @schema sysname  declare @table sysname  declare @count int  declare @sqlcommand varchar(8000)  declare @where varchar(8000)  declare @columnname sysname  declare @object_id int   set @stringtofind = '\20160521\' --//production server ip set @stringtoreplace = '\2016\05\21\' --//backup server ip  declare tab_cursor cursor   select   b.name      schemaname,           a.name      tablename,           a.object_id      sys.objects           inner join sys.schemas b             on a.schema_id = b.schema_id     type = 'u'  order 1   open tab_cursor   fetch next tab_cursor  @schema,       @table,       @object_id   while @@fetch_status = 0    begin      declare col_cursor cursor      select a.name        sys.columns             inner join sys.types b               on a.system_type_id = b.system_type_id       object_id = @object_id             , is_computed = 0             , b.name in ('char','nchar','nvarchar','varchar','text','ntext')       open col_cursor       fetch next col_cursor      @columnname       while @@fetch_status = 0        begin          set @sqlcommand = 'update ' + @schema + '.' + @table + ' set [' + @columnname                             + '] = replace(convert(nvarchar(max),[' + @columnname + ']),'''                             + @stringtofind + ''',''' + @stringtoreplace + ''')'           set @where = ' [' + @columnname + '] ''%' + @stringtofind + '%'''           exec( @sqlcommand + @where)           set @count = @@rowcount           if @count > 0            begin              print @sqlcommand + @where              print 'updated: ' + convert(varchar(10),@count)              print '----------------------------------------------------'            end           fetch next col_cursor          @columnname        end       close col_cursor      deallocate col_cursor       fetch next tab_cursor      @schema,           @table,           @object_id    end   close tab_cursor  deallocate tab_cursor 

issue have run query whole 2016 year , every day of 12 months, can me value ;
@stringtofind = '\20160521\' increment 20160501 20160530 @stringtoreplace = '\2016\05\21\' increment 2016/05/01 2016/05/30

increments automatically @ least month 30 days


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -