【问题标题】:Inserting 2 insert query records in SQL server在 SQL Server 中插入 2 个插入查询记录
【发布时间】:2017-01-15 15:19:49
【问题描述】:

需要你的专家

当插入这样的查询时:

use tabelmantap
delete from T_CekUser
insert into T_CekUser(T_21SI)
select tbla.MASA
from
(
select * from T_21SI
union
select * from T_21SI
) as tbla
where tbla.THN_DATA = '2014' and tbla.KEY_NPWP = '01.576.555.5-123.000'
insert into T_CekUser(T_23SI)
select tblb.MASA from
(
select * from T_23SI
union
select * from T_23SI
) as tblb
where tblb.THN_DATA = '2014' and tblb.KEY_NPWP = '01.576.555.5-123.000'

所有查询都在 sql server 中的一行/一页查询中

我得到这样的结果:

T_21SI  |  T_23SI
1           null
2           null
3           null
4           null
null         2
null         3

累了,四处寻找答案或解决方案,因为我想成为这样:

T_21SI  |  T_23SI
1            2
2            3
3            null
4            null
null         null
null         null

所有文件类型都是 int

我已经从两个表中使用 select 进行插入(使用内部联接),但结果不是预期的

任何帮助将不胜感激..谢谢

【问题讨论】:

  • 实际上,您似乎正在尝试执行 PIVOT 我假设每一行都有特定的含义?
  • 好吧..数据是月份数..是的,它的支点..知道如何不使用联合来支点该数据

标签: sql-server


【解决方案1】:

尝试使用 PIVOT 语句的详细信息在这里。 https://technet.microsoft.com/en-us/library/ms177410(v=sql.105).aspx

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-09
    • 2016-03-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多