sql存储过程判断问题求助
小弟写了个存储过程。但是提示我else附近有错误,但是我仔细看了没有发现有错误呀。所以想请求各位大神帮帮忙给我看看那的问题下面是代码。。。。在线等。急
CREATE PROC sp_gzfjb
@id int
AS
declare @fid int
declare @gzrw nvarchar(max)
declare @zxr nvarchar(max)
declare @main_id int
declare @jihuakaishi datetime
declare @jihuajieshu datetime
declare @rwjd nvarchar(max)
declare @ts int
declare @ri datetime
select @main_id=c2.id,@fid=c6.id,@gzrw=c2.工作任务,@zxr=c2.任务人,@rwjd=c6.任务阶段,@jihuakaishi=c6.计划开始,@jihuajieshu=c6.计划结束 FROM C20120822094542 as c2 INNER JOIN S20120822094606 as c6 ON c2.任务跟中=c6.main_id WHERE c2.id=@id
SELECT @ts=DATEDIFF(day,@jihuakaishi,@jihuajieshu)+1
declare @ii int
set @ii=0
while @ii<@ts
BEGIN
if (@rwjd='开始' or @rwjd='评估' or @rwjd='工作评估')
ELSE
BEGIN
if(@ii=0)
Select @ri=DATEADD(dd,+1,@jihuakaishi)
ELSE
BEGIN
Select @ri=DATEADD(dd,+1,@ri)
END
insert into GZFJ (Main_id,工作名称,父工作ID,工作日期,执行人,分解次数,完成状态) values(@main_id,@gzrw+(ii+1/@ts),@fid,@ri,@zxr,'1','0')
END
set @ii=@ii+1
END
------解决方案--------------------CREATE PROC sp_gzfjb
@id int
AS
declare @fid int
declare @gzrw nvarchar(max)
declare @zxr nvarchar(max)
declare @main_id int
declare @jihuakaishi datetime
declare @jihuajieshu datetime
declare @rwjd nvarchar(max)
declare @ts int
declare @ri datetime
select @main_id=c2.id,@fid=c6.id,@gzrw=c2.工作任务,@zxr=c2.任务人,@rwjd=c6.任务阶段,@jihuakaishi=c6.计划开始,@jihuajieshu=c6.计划结束 FROM C20120822094542 as c2 INNER JOIN S20120822094606 as c6 ON c2.任务跟中=c6.main_id WHERE c2.id=@id