2010-08-28 58 views
0

此表值函数编译好的时候抛出..附近有语法错误,SQL 2005 - 表值函数编译确定,但选择

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

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

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

您还必须将所包含的单曲翻倍。

当SET QUOTED_IDENTIFIER为ON时,“划一个对象/列名等不是字符串,这是默认设置过于

SET QUOTED_IDENTIFIER OFF has no meaning at runtime:。它被设置在创建/更改时间......这是为什么你在运行时得到的错误不是创建时间CREATE <>编译的方式...它在编译时计划在运行时

+0

感谢您对Quoted_identifer的说明.. 我确实改变了select语句来翻转single和双引号与对方..但仍然是相同的.. – TonyP 2010-08-28 14:38:03

+0

TonyP:我的意思是双倍,那就是“不” – gbn 2010-08-28 14:46:35