【问题标题】:Creating a temp table and using aggregate select query创建临时表并使用聚合选择查询
【发布时间】:2018-12-02 04:08:00
【问题描述】:

我正在尝试从子选择查询创建临时表,但收到一条错误消息

消息 102,第 15 级,状态 1,第 5 行
';' 附近的语法不正确

这是我的查询:

select * 
into #temp 
from
    (select dollars,  PostingDate, EntryDescription
     from MillsEntOps.dbo.OE_InvoiceGLSumm 
     where Postingdate between '2018/03/01' and '2018/04/11')

错误信息是:

消息 102,第 15 级,状态 1,第 5 行
')' 附近的语法不正确。

任何想法我做错了什么?

【问题讨论】:

  • 您的查询没问题。只有您需要为子查询添加别名。否则sql无法识别。因此,您收到此错误消息。

标签: sql sql-server temp-tables


【解决方案1】:

或者你可以写:

select dollars,  PostingDate, EntryDescription
into #TEMP
from MillsEntOps.dbo.OE_InvoiceGLSumm 
where Postingdate between '2018/03/01' and '2018/04/11'

【讨论】:

    【解决方案2】:

    我想你错过了别名

    select * into #temp from ( select dollars, PostingDate, EntryDescription from MillsEntOps.dbo.OE_InvoiceGLSumm where Postingdate between '2018/03/01' and '2018/04/11')temp_table /* alias name temp_table */
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-24
      • 2021-09-14
      • 2022-11-22
      相关资源
      最近更新 更多