如何在sql server 2017中选择除某些列以外的所有列?

4xrmg8kj  于 2021-08-13  发布在  Java
关注(0)|答案(1)|浏览(402)

我有很多查询加入到一个查询中,这些查询加入一个id列,这个列重复这个id列。

select t1.* , t2.* , t3.* , ...
from (query1) as t1 , (query2) as t2 , (query3) as t3 , ...
where t1.id1 = t2.id2 and t1.id1 = t3.id3 and ...

查询有许多列,我想在每个查询中选择除某些列以外的所有列。
例如:

select 
    t1.(all columns except some columns), 
    t2.(all columns except some columns),
    t3.* , ...
from 
    (query1) as t1 , (query2) as t2 , (query3) as t3 , ...
where
     t1.id1 = t2.id2 and t1.id1 = t3.id3 and ...

如何选择sql 17中除某些列以外的所有列?谢谢你的建议。

zaq34kh6

zaq34kh61#

这只是一个工作-

-- In step 1 insert your query output to a temp table
SELECT *
INTO #Temp
FROM
(
   select t1.* , t2.* , t3.* , ...
   from (query1) as t1 , (query2) as t2 , (query3) as t3 , ...
   where t1.id1 = t2.id2 and t1.id1 = t3.id3 and ...
)

-- Then drop all columns from the temp table you wants to exclude 
-- from your final selection
ALTER TABLE #Temp
DROP COLUMN column_name1, column_name2

-- Finally, just select all records from temp table
SELECT * FROM #Temp

相关问题