问题提示:“在函数内不正确地使用了 'getdate'” 各位大侠帮帮我
创建函数语句如下:
CREATE FUNCTION fn_getQkItem ( @chvTradeGUID varchar ( 40 ))
RETURNS varchar ( 200 )
AS
BEGIN
declare @chvItemName varchar ( 200 )
set @chvItemName = ' '
select @chvItemName = @chvItemName + ', ' + s_Fee . ItemName
from s_Fee
where s_Fee . TradeGUID = cast ( @chvTradeGUID as uniqueidentifier ) and s_Fee . Ye > 0 and
s_Fee . LastDate <= getdate () and ItemType in ( ' 非贷款类房款 ' , ' 贷款类房款 ' )
if @chvItemName <> ' '
set @chvItemName =right( @chvItemName , len ( @chvItemName )- 1 )
return @chvItemName
END
然后抱错:
服务器: 消息 443,级别 16,状态 1,过程 fn_getQkItem,行 19
在函数内不正确地使用了 'getdate '。
各位大哥我是菜鸟,刚接触数据库,如有哪位知道,小弟感激不尽,请回答的时候尽量详细,谢谢
------解决方案--------------------加个dbo就可以了:
CREATE FUNCTION fn_getQkItem ( @chvTradeGUID varchar ( 40 ))
RETURNS varchar ( 200 )
AS
BEGIN
declare @chvItemName varchar ( 200 )
set @chvItemName = ' '
select @chvItemName = @chvItemName + ', ' + s_Fee . ItemName
from s_Fee
where s_Fee . TradeGUID = cast ( @chvTradeGUID as uniqueidentifier ) and s_Fee . Ye > 0 and
s_Fee . LastDate <= dbo.getdate () and ItemType in ( ' 非贷款类房款 ' , ' 贷款类房款 ' )
if @chvItemName <> ' '
set @chvItemName =right( @chvItemName , len ( @chvItemName )- 1 )
return @chvItemName
END
------解决方案--------------------CREATE FUNCTION fn_getQkItem ( @chvTradeGUID varchar ( 40 ))
RETURNS varchar ( 200 )
AS
BEGIN
declare @chvItemName varchar ( 200 )
set @chvItemName = ' '
select @chvItemName = @chvItemName + ', ' + s_Fee . ItemName
from s_Fee
where s_Fee . TradeGUID = cast ( @chvTradeGUID as uniqueidentifier ) and s_Fee . Ye > 0 and
s_Fee . LastDate <= (select top 1 Currentdate from dbo.[V_getdate]) and ItemType in ( ' 非贷款类房款 ' , ' 贷款类房款 ' )
--改了上面
if @chvItemName <> ' '
set @chvItemName =right( @chvItemName , len ( @chvItemName )- 1 )
return @chvItemName
END