Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.
One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.
create procedure abcd ( @tblsource VARCHAR(100) ,@tbltarget varchar(100) ,@no_of_cols int ) AS BEGIN declare @select varchar(max),@where varchar(max),@sql varchar(max) -- Get the column names SELECT @where = STUFF(( SELECT ',['+ COLUMN_NAME+']' FROM INFORMATION_SCHEMA.columns where table_name = @tblsource and ORDINAL_POSITION <= @no_of_cols ORDER BY ',['+ COLUMN_NAME+']' FOR XML PATH('')), 1, 1, '') -- Create the target table select @sql = ' IF OBJECT_ID('''+@tblTarget+''') IS NOT NULL DROP TABLE ' + @tblTarget +' select '+@where+ ' into '+@tblTarget+' from ' + @tblSource + ' where 1 = 0' exec(@sql) select @select = substring(select_list,1,len(select_list)-5) from ( select stuff((select 'SELECT ''' + COLUMN_NAME + ''' colname,'+COLUMN_NAME+' data FROM ' + @tblsource + ' WHERE ISNULL('+COLUMN_NAME+','''') <> '''' UNION ' from INFORMATION_SCHEMA.columns where table_name = @tblsource and ORDINAL_POSITION <= @no_of_cols order by COLUMN_NAME for xml path(''), type).value('.','nvarchar(max)') , 1, 0, '') as select_list) t1 select @sql = ' ;with cte as ( select *,ROW_NUMBER() over (partition by colname order by data) rn from ('+@select+') t1) insert ' + @tblTarget + ' select '+@where+' from cte pivot (max(data) for colname in ('+@where+') ) p' exec(@sql) end
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
Join the community of 500,000 technology professionals and ask your questions.