---- 建立测试环境:
create table table1(a int identity,b varchar(20),c datetime,d datetime,e int)
create proc proc1
@c datetime,
@d datetime,
@e int
as 
declare @f int
insert table1 (c,d,e) values(@c,@d,@e)
select @f=@@identity
if @@error=0
begin 
update table1 set b=convert(varchar,a)+convert(varchar(12),d,120) where a=@f
end ---执行存储过程
exec proc1 '2001-10-01','2001-10-20',45select * from table1

解决方案 »

  1.   

    楼上各位其实难在怎样在插入数据前可以读取这条记录自动生成的自动编号啊?至于B怎样处理无所谓,我实际应用是还要加上好多东西啊!!
    B为VARCHAR啊!
      

  2.   

    如果b是datetime 的话:
    create table table1(a int identity,b datetime,c datetime,d datetime,e int)
    create proc proc1
    @c datetime,
    @d datetime,
    @e int
    as 
    declare @f int
    insert table1 (c,d,e) values(@c,@d,@e)
    select @f=@@identity
    if @@error=0
    begin 
    update table1 set b=left(convert(varchar(10),@d,120),8)+
    convert(varchar(4),datepart(dd,@d)+@f) where a=@f
    end ---执行存储过程
    exec proc1 '2001-10-01','2001-10-20',45
    select * from table1
    -------------------------
    如果b是int 的话:
    create table table1(a int identity,b int,c datetime,d datetime,e int)create proc proc1
    @c datetime,
    @d datetime,
    @e int
    as 
    declare @f int
    insert table1 (c,d,e) values(@c,@d,@e)
    select @f=@@identity
    if @@error=0
    begin 
    update table1 set b=@f+datepart(dd,@d) where a=@f
    end 
      

  3.   

    哦,b 为varchar 呀,那我的第一个写法就可以啦
      

  4.   

    请问一下 @@identity 是不是只有表中存在有自动增长的字段才能使用吗?普通的能使用吗?如果可以会返回什么东西啊?
      

  5.   

    create procedure proname
    (
     @c varchar(50),
     @d varchar(50),
     @e varchar(50)
    )declare @a int ,
                   @b varchar(50)select @a = nullselect @a  = max(a) from table1if @a is null 
       select @a = 1
    else
      select @a = @a+1select @b = convert(varchar(50),@a)+convert (varchar(50),getdate(),20)insert into table1
    (a,b,c,d,e)
    values
    (@a,@b,@c,@d,@e)----------
    大概的思路是这样子的,数据类型我不太清楚你的,所以暂时设置为varchar