Sql server SQL Server 2012,排除列

Sql server SQL Server 2012,排除列,sql-server,duplicates,Sql Server,Duplicates,我有SQL查询 ; with cte as ( SELECT PARSENAME(REPLACE(replace(replace(replace(replace(dbo.IDENTITY_MAP.Name, 'My Company\', ''), '-VLAN2', ''), '.VLAN2\', ''), '.Instr\', '') , '\' , '.'), 1) as "Site", Count (CASE WHEN

我有SQL查询

; with cte as 
(
   SELECT 
       PARSENAME(REPLACE(replace(replace(replace(replace(dbo.IDENTITY_MAP.Name, 'My Company\', ''), '-VLAN2', ''), '.VLAN2\', ''), '.Instr\', '') , '\' , '.'), 1) as "Site",
       Count (CASE
                 WHEN dbo.SEM_AGENT.AGENT_VERSION LIKE '11.%' THEN 1
              END) AS 'SEP-11',
       Count (CASE
                 WHEN dbo.SEM_AGENT.AGENT_VERSION LIKE '12.%' THEN 1
              END) AS 'SEP-12',
   FROM   
       dbo.sem_computer
   INNER JOIN 
       [dbo].[V_SEM_COMPUTER] ON [dbo].[V_SEM_COMPUTER].COMPUTER_ID = SEM_COMPUTER.COMPUTER_ID
   WHERE 
       dbo.IDENTITY_MAP.Name NOT LIKE '%Servers%'
   GROUP BY 
       PARSENAME(REPLACE(replace(replace(replace(replace(dbo.IDENTITY_MAP.Name,'My Company\',''),'-VLAN2',''),'.VLAN2\',''),'.Instr\','') , '\' , '.'),1)
)
select *
from cte
join SEPM_site ss on cte.Site = ss.Site
这给了我想要的输出------几乎就是

Site  SEP-11  SEP-12 Rackcode  Circuit  Site
对于
站点
,我只需要一列

我尝试用这些列重新创建一个临时表,并将其删除,即

; with cte as (SELECT ...)
select * into temptable
from cte
join SEPM_site ss
 on cte.Site = ss.Site
alter table temptable
drop column cte.Site
select * from temptable
drop table temptable
但我有一个错误

“.”附近的语法不正确

如果我没有指定哪个表
Site
来自哪个表,我会得到一个错误

每个表中的列名必须是唯一的。多次指定了表“TESTERABLE”中的列名“Site”

但这就是为什么我试图删除重复列


谢谢

只需在select语句中指定所需的列:

select cte.Site, cte.[SEP-11], cte.[SEP-12], ss.Rackcode, ss.Circuit
from cte
join SEPM_site ss
 on cte.Site = ss.Site
您还可以选择cte中的所有列以及ss中所需的列:

select cte.*, ss.Rackcode, ss.Circuit
from cte
join SEPM_site ss
 on cte.Site = ss.Site