不好意思,新手问各位个白痴问题:
请问sql中调用一个自定义函数修改数据库表中一个字段在值,sql语句怎么写啊?
谢谢各位!

解决方案 »

  1.   

    udpate 表名 set 字段名=自定义函数名(参数列表) where 条件
      

  2.   

    不好意思,上面把 update 写错了。
    update 表名 set 字段名=自定义函数名(参数列表) where 条件
      

  3.   

    SQL codeudpate 表名set 字段名=自定义函数名(参数列表)where 条件
      

  4.   

    create   function   f_ch2py(@chn   nchar(1))   
      returns   char(1)   
      as   
      begin   
      declare   @n   int   
      declare   @c   char(1)   
      set   @n   =   63   
        
      select   @n   =   @n   +1,   
                    @c   =   case   chn   when   @chn   then   char(@n)   else   @c   end   
      from(   
        select   top   27   *   from   (   
                select   chn   =     
      '吖'   union   all   select   
      '八'   union   all   select   
      '嚓'   union   all   select   
      '咑'   union   all   select   
      '妸'   union   all   select   
      '发'   union   all   select   
      '旮'   union   all   select   
      '铪'   union   all   select   
      '丌'   union   all   select     --because   have   no   'i'   
      '丌'   union   all   select   
      '咔'   union   all   select   
      '垃'   union   all   select   
      '嘸'   union   all   select   
      '拏'   union   all   select   
      '噢'   union   all   select   
      '妑'   union   all   select   
      '七'   union   all   select   
      '呥'   union   all   select   
      '仨'   union   all   select   
      '他'   union   all   select   
      '屲'   union   all   select     --no   'u'   
      '屲'   union   all   select     --no   'v'   
      '屲'   union   all   select   
      '夕'   union   all   select   
      '丫'   union   all   select   
      '帀'   union   all   select   @chn)   as   a   
      order   by   chn   COLLATE   Chinese_PRC_CI_AS     
      )   as   b   
      return(@c)   
      end   
      
    调用时:
    update LsItem set py=f_ch2py(参数列表) where itemcode='001336'我是写在提取拼音字母的函数,那么用他的时候,“参数列表”要写什么呢?
      

  5.   

    update LsItem set py=f_ch2py(PY)//PY 是这个字段的名
    或update LsItem set py=f_ch2py('PY')
    这两个执行以后都说:'f_ch2py' 不是可以识别的函数名。
    该数据库中已经策创建了那个函数了啊!请问还会是什么问题呢?
      

  6.   

    @chn这个时候你需要让他等于啥就写啥啊
      

  7.   

    你确定数据库中有 f_ch2py 这个自定义函数吗?看一下 f_ch2py 的所有都是什么,比如是 dbo,则这样试试:
    update LsItem set py=dbo.f_ch2py(py) where itemcode='001336'
      

  8.   

    谢谢空军!还真要那样!加上dbo就没事了!