Click here to Skip to main content
15,904,024 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
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



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..
Posted

1 solution

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[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900