| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 875 人关注过本帖
标题:用户自定义函数错误
只看楼主 加入收藏
fengmumei
Rank: 2
等 级:论坛游民
威 望:2
帖 子:298
专家分:14
注 册:2006-9-16
结帖率:100%
收藏
 问题点数:0 回复次数:3 
用户自定义函数错误
今天写了自定义函数,执行查询没有问题,但是具体运行时就总是报错
服务器: 消息 208,级别 16,状态 1,过程 chmxzb,行 26
对象名 '@liushuizh' 无效。

查了一些资料,“服务器: 消息 208,级别 16,状态 1”说明相应表不存在,但是函数中涉及的两个表格@djb,@liushuizh都是存在的,而且运行实例时也只是提示@liushuizh不存在,并没有提示@djb不存在。查了一上午的资料也没有找到原因,请大家伙帮个忙看看。
函数的具体内容如下:
create function chmxzb(@gsmc varchar(50),@ckmc varchar(10),@wpbh varchar(10),@rqtj varchar(200))
returns @chmxzb table
(
        rq1 datetime,
        djh varchar(9),
        czlx varchar(20),
        sname varchar(200),
        zyxx varchar(200),
        rshliang decimal(18,2),
    rdj decimal(18,2),
    rje decimal(18,2),
    cshliang decimal(18,2),
    cdj decimal(18,2),
    cje decimal(18,2)
      )  
as  
 begin
       declare @djb varchar(6)
       declare @liushuizh varchar(20)      
       select @djb=djb,@liushuizh=zhangbiao from gongsibiao where gsmc=@gsmc and nian='2008'
      
         if @ckmc<>'工程库'            
            insert into @chmxzb select convert(char(20),rq,20) as rq1,[@djb].djh,czlx,sname,case when czlx='调出' then '调往'+sname else sname+czlx end as zyxx,case when czlx in ('采购进货','调入') then shliang when czlx='采购退货' then -shliang else null end as rshliang,case when czlx in ('采购进货','调入','采购退货') then bhsdj  else null end as rdj,case when czlx in ('采购进货','调入') then bhsje when czlx='采购退货' then -bhsje else null end as rje,case when czlx in ('领用出库','销售出库','调出') then shliang when czlx in('领用退库','销售退库') then -shliang else null end as cshliang,case when czlx in ('领用出库','销售出库','领用退库','销售退库','调出') then bhsdj  else null end as cdj,case when czlx in ('领用出库','销售出库','调出') then bhsje when czlx in('领用退库','销售退库') then -bhsje else null end as cje from [@djb],[@liushuizh] where [@djb].djh=[@liushuizh].djh and [@liushuizh].zfbz=0 and [@djb].zfbz=0  and ckmc=@ckmc and wpbh=@wpbh+@rqtj
         else            
            insert into @chmxzb select convert(char(20),rq,20) as rq1,[@djb].djh,czlx,sname,case when czlx='调出' then '调往'+sname else sname+czlx end as zyxx,case when czlx in ('采购进货','调入') then shliang when czlx='采购退货' then -shliang else null end as rshliang,case when czlx in ('采购进货','调入','采购退货') then hsdj  else null end as rdj,case when czlx in ('采购进货','调入') then zjiner when czlx='采购退货' then -zjiner else null end as rje,case when czlx in ('领用出库','销售出库','调出') then shliang when czlx in('领用退库','销售退库') then -shliang else null end as cshliang,case when czlx in ('领用出库','销售出库','领用退库','销售退库','调出') then hsdj  else null end as cdj,case when czlx in ('领用出库','销售出库','调出') then zjiner when czlx in('领用退库','销售退库') then -zjiner else null end as cje from [@djb],[@liushuizh] where [@djb].djh=[@liushuizh].djh and [@liushuizh].zfbz=0 and [@djb].zfbz=0  and ckmc=@ckmc and wpbh=@wpbh+@rqtj
       return
 end
搜索更多相关主题的帖子: 函数 定义 用户 
2008-05-08 14:13
happynight
Rank: 8Rank: 8
等 级:贵宾
威 望:15
帖 子:807
专家分:760
注 册:2008-4-26
收藏
得分:0 
你想动态执行SQL语句好象不能这样吧,必须使用Execute吧 我说的是2000版本
之后的版本未使用过 不只是否如此
2008-05-08 14:21
fengmumei
Rank: 2
等 级:论坛游民
威 望:2
帖 子:298
专家分:14
注 册:2006-9-16
收藏
得分:0 
你是说insert into 那句么?

随缘不变,不变随缘
2008-05-08 14:23
fengmumei
Rank: 2
等 级:论坛游民
威 望:2
帖 子:298
专家分:14
注 册:2006-9-16
收藏
得分:0 
直接从指定表中度数据是没有问题的,是不是用户自定义函数不支持动态执行啊?

随缘不变,不变随缘
2008-05-08 14:25
快速回复:用户自定义函数错误
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014893 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved