用户在sqlserver中定义的函数 [英] User defined Functions in sqlserver

查看:61
本文介绍了用户在sqlserver中定义的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

create function get_code()
 returns char(10)
  as begin declare @lastval char(5)
   set @lastval = (select max(advisor_code) from tbl_advisor_table)
    if @lastval is null set @lastval = 'DFP'
     declare @i int set @i = right(@lastval,4) + 1
     return 'C' + right('000' + convert(varchar(10),@i),4)

      end







这是我的功能



alter table tbl_advisor_table add adviso r_code uniqueidentifier默认get_code()



表示



'get_code'不是公认的内置功能名称。



我继续尝试..




this is my fuction

alter table tbl_advisor_table add advisor_code uniqueidentifier default get_code()

its says

'get_code' is not a recognized built-in function name.

im keep trying..

推荐答案

我们无法将用户定义的功能分配给uniqueIdentifer所以它是错误的,请在更改表时将get_Code()替换为NEWID()


参考:



http: //social.msdn.microsoft.com/Forums/en-US/8f7e0fed-f243-4593-b9e1-63ab130f5f3c/can-a-uniqueidentifier-have-a-default-value [ ^ ]



HT tp://technet.microsoft.com/en-us/library/ms189786%28v=sql.105%29.aspx [ ^ ]
we cannot assign user defined function to uniqueIdentifer so it is giving error please replace get_Code() as NEWID() while altering table

References:

http://social.msdn.microsoft.com/Forums/en-US/8f7e0fed-f243-4593-b9e1-63ab130f5f3c/can-a-uniqueidentifier-have-a-default-value[^]

http://technet.microsoft.com/en-us/library/ms189786%28v=sql.105%29.aspx[^]


这篇关于用户在sqlserver中定义的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆