自己做一个函数,然后写在公式里--方法1.创建一个自定义函数,得到最新编号
create function f_getid()
returns char(6)
as
begin
declare @re char(6)
select @re=max(编号字段) from 表
if @re is null 
set @re='000001'
else
set @re=right('000000'+cast(cast(@re as bigint)+1 as varchar),6)
return(@re)
end
go--将编号字段的默认值设置为f_getid()
create table 表(编号字段 char(6) default 'ABC'+dbo.f_getid())

解决方案 »

  1.   

    输入数据时,出错:
    [Microsoft][ODBC server driver][sql server]将截断字符串或二进制数据
    [Microsoft][ODBC server driver][sql server]语句终止谢谢to solidpanther(╃╄╃我爱机器猫╄╃╄)
      

  2.   

    [Microsoft][ODBC server driver][sql server]将类型varchar转换为bigint时出错
    to solidpanther(╃╄╃我爱机器猫╄╃╄)
      

  3.   

    这回对了:)
    drop table 表
    go
    drop function dbo.f_getid
    gocreate function f_getid()
    returns char(6)
    as
    begin
    declare @re char(6)
    select @re=max(replace(编号字段,'abc','')) from 表
    if @re is null 
    set @re='000001'
    else
    set @re=right('000000'+cast(cast(@re as bigint)+1 as varchar),6)
    return(@re)
    end
    go--将编号字段的默认值设置为f_getid()
    create table 表(aaa varchar(100),编号字段 char(100) default 'ABC'+dbo.f_getid())