繁体   English   中英

Select 除 ONE 之外的所有列,使用 SQL 服务器

[英]Select all columns except ONE with SQL server

我从 SQL 服务器开始。 我加入了两张桌子。 它们都包含一个名为“id”的列。

在内连接之后,我现在有两个具有相同名称(“id”)的列。

我该如何解决这个问题(-无需输入我想保留的所有列。我有 200 列-)。

declare @contract_number nvarchar(255) = '2019.37080'
declare @reportingperiod nvarchar(255) = '2019-Q1'
 

select *
from ifrs17.output_bba
inner join ifrs17.unit_of_account 
    on unit_of_account.contract_number = output_bba.unit_of_account_number
    and unit_of_account.reporting_period = output_bba.reporting_period
    and unit_of_account.currency_source = output_bba.currency_source
where 
    output_bba.unit_of_account_number = @contract_number
    and output_bba.meta_id in ( select max(meta_id) from ifrs17.output_bba where contract_number = @contract_number and legal_entity_code = 'SR' group by reporting_period )
    and unit_of_account.meta_id in ( select max(meta_id) from ifrs17.unit_of_account where contract_number = @contract_number and legal_entity_code = 'SR' group by reporting_period )
    and output_bba.time_index > 0
    and output_bba.reporting_period = @reportingperiod

您无需键入列名。 拖放作品。

打开 SSMS Object 资源管理器。 单击数据库。 单击您的数据库。 单击表格。 单击表格。 您将看到“列”。 将“列”(label,而不是单个列名)拖到查询 window 中。 所有列名都显示为逗号分隔的列表。 将“id”更改为“id as FirstID”,对第二个表重复此操作。 当您使用需要指定列名的“SET IDENTITY_INSERT”时也很有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM