【问题标题】:I can't make a query select into in 2 table我无法在 2 个表中进行查询选择
【发布时间】:2020-05-28 14:54:40
【问题描述】:

“在 orderUK 表中查询employeeUK 的所有员工订单”

我的employeeUK表:

select *
into employeeUK
from Employees
where Country = 'UK'

然后我想制作 orderUK 表,但我很困惑,因为我的查询总是出错。 查询应该如何?

【问题讨论】:

    标签: sql sql-server insert sql-insert


    【解决方案1】:

    问题是您是在为 Perm 表创建一个临时表。表是否已经存在。

    如果您要创建临时表,请使用以下内容

    Select * 
    Into #employeeUK
    From Employees
    Where Country = 'UK'
    

    如果这要进入 Perm 表,只要该表不存在,您就可以使用相同的代码。

    如果表已经存在,则使用此代码。

    Insert Into employeeUK
    Select * 
    From Employees
    Where Country = 'UK'
    

    请记住,临时表以“#”开头,而不是 perm 表。

    【讨论】:

      【解决方案2】:

      您必须从要插入数据的表开始。

      into employeeUK
      select *
      from Employees
      where Country = 'UK'
      

      【讨论】:

        猜你喜欢
        • 2012-10-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-06-24
        • 2014-03-12
        • 2021-12-14
        • 2016-11-12
        • 1970-01-01
        相关资源
        最近更新 更多