sql server - I have managed to create a view statment with all the columns I need. Can I use it to somehow get also the table view that I need? -
in table
there 120 columns. need 117 columns listed. script selects columns need.
select column_name information_schema.columns table_name = 'table' , column_name not in ( 'columna' ) , column_name not in ( 'columnb' ) , column_name not in ( 'columnc' )
can use script generate table need? how? if not, there other solution (other writing down 120 , deleting 3)?
you need use dynamic sql
declare @col_list varchar(max)= '' set @col_list = (select ',' + column_name information_schema.columns table_name = 'table' , column_name not in ( 'columna', 'columnb', 'columnc' ) xml path ('')) select stuff(@col_list, 1, 1, '') exec ('select '+@col_list+' yourtable ')
Comments
Post a Comment