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

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -