---- 建立测试环境:
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
B为VARCHAR啊!
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
(
@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