sql - Execute dynamic query result using stored procedure -
the below query return 60 rows, how can execute statements using stored procedure in single go.
select 'update temp1 set ' + column_name + '= 0' + ' '+column_name+ ' null' information_schema.columns table_name = 'temp1' , data_type = 'float' , column_name not in('sales','net_margin');
here 1 way it:
declare @sql nvarchar(max) = '' select @sql = @sql + 'update temp1 set ' + column_name + '= 0' + ' '+column_name+ ' null; ' information_schema.columns table_name = 'temp1' , data_type = 'float' , column_name not in('sales','net_margin'); print @sql -- remark row once check sql , unremark next 1 execute --exec(@sql)
Comments
Post a Comment