代码之家  ›  专栏  ›  技术社区  ›  TonyP

SQL 2005-表值函数编译正常,但在附近引发不正确的语法。当选择

  •  0
  • TonyP  · 技术社区  · 14 年前

    此表值函数编译成功,

    alter function [dbo].[ftsls031nnnHades](@withExpiredEntries smallint ) returns 
    @t table( comno     varchar(3), 
            t$cuno      varchar(6),
            t$cpgs      varchar(6),
            t$dile      float,
            t$qanp      float,
            t$stdt      varchar(10),
            t$tdat      varchar(10),
            t$disc      float,
            t$damt      float,
            t$cdis      char(3),
            t$gnpr      float,
            t$refcntd   float,
            t$refcntu   float) as
    ------------------------------------------------------*/
    /*-------------------------------------------------------
    declare @withExpiredEntries bit; set @withExpiredEntries =0
    declare @t table( comno     varchar(3), 
            t$cuno      varchar(6),
            t$cpgs      varchar(6),
            t$dile      float,
            t$qanp      float,
            t$stdt      varchar(10),
            t$tdat      varchar(10),
            t$disc      float,
            t$damt      float,
            t$cdis      char(3),
            t$gnpr      float,
            t$refcntd   float,
            t$refcntu   float)
    ------------------------------------------------------*/
    Begin
    set quoted_identifier off
    if (@withExpiredEntries = 0) -- without expired entries
        Begin
            insert @t
            select * 
            from openQuery(Hades ,"select '010' comno, trim(t$cuno) t$cuno,trim(t$cpgs) t$cpgs,t$dile,t$qanp,to_char(t$stdt,'dd Mon yy') t$stdt,to_char(t$tdat,'dd Mon yy') t$tdat,to_char(t$disc,'999.99') t$disc,t$damt,t$cdis,t$gnpr,t$refcntd,t$refcntu from baan.ttdsls031010 where (to_char(t$Tdat,'yyyy-mm-dd') >= To_char(current_date,'yyyy-mm-dd')) and (to_char(t$stdt,'yyyy-mm-dd') <= To_char(current_date,'yyyy-mm-dd')) 
                   union all       select '020' comno, trim(t$cuno) t$cuno,trim(t$cpgs) t$cpgs,t$dile,t$qanp,to_char(t$stdt,'dd Mon yy') t$stdt,to_char(t$tdat,'dd Mon yy') t$tdat,to_char(t$disc,'999.99') t$disc,t$damt,t$cdis,t$gnpr,t$refcntd,t$refcntu from baan.ttdsls031020 where (to_char(t$tdAt,'yyyy-mm-dd') >= To_char(current_date,'yyyy-mm-dd')) and (to_char(t$stdt,'yyyy-mm-dd') <= To_char(current_date,'yyyy-mm-dd'))")
        return  
    End
        insert @t
        select * 
            from openQuery(Hades ,"select '010' comno, trim(t$cuno) t$cuno,trim(t$cpgs) t$cpgs,t$dile,t$qanp,to_char(t$stdt,'dd Mon yy') t$stdt,to_char(t$tdat,'dd Mon yy') t$tdat,to_char(t$disc,'999.99') t$disc,t$damt,t$cdis,t$gnpr,t$refcntd,t$refcntu from baan.ttdsls031010  
                   union all       select '020' comno, trim(t$cuno) t$cuno,trim(t$cpgs) t$cpgs,t$dile,t$qanp,to_char(t$stdt,'dd Mon yy') t$stdt,to_char(t$tdat,'dd Mon yy') t$tdat,to_char(t$disc,'999.99') t$disc,t$damt,t$cdis,t$gnpr,t$refcntd,t$refcntu from baan.ttdsls031020   ")
        return
    end
    

    选中时引发此错误

    消息102,级别15,状态1,行1 'select'010'comno附近有语法错误,trim(t$cuno)t$cuno,trim(t$cpgs)t$cpgs,t$dile,t$qanp,to_char(t$stdt,'dd mon yy')t$stdt,to_char(t$tdat,'dd'。

    1 回复  |  直到 14 年前
        1
  •  1
  •   gbn    14 年前

    将双引号改为单引号,看看会发生什么…

    ...
    ..Hades ,'select '010' comno...
    ...
    

    你也得把包含的单曲加倍。

    当set quoted_identifier为on时,“分隔对象/列名等,而不是字符串。”这也是默认设置。

    这个 SET QUOTED_IDENTIFIER OFF has no meaning at runtime :设置为创建/更改时间…这就是为什么在运行时得到错误而不是创建时间。创建<gt;编译方式…它在运行时编译成一个计划。

    推荐文章