前面已经定义了@sDate @eDate的类型是datetime,但执行语句1的话 调用存储过程报错, 而执行语句2就可以正常查询. 这是为什么?怎么解决 大致代码如下, 同样的语句执行结果集1可以正常运行, 就是执行结果集2的时候会报错 -----结果集1 INSERT INTO #JZ_1 SELECT * FROM a WHERE 1=1 and j.DATE >= @sDate AND j.DATE < @eDate AND C.CORP=@CORP SELECT @l_error = @@error IF @l_error <> 0 BEGIN ROLLBACK TRAN tran_JZ RETURN 1 END -----结果集2 INSERT INTO #JZ_1 SELECT * FROM b WHERE 1=1 and j.DATE >= @sDate AND j.DATE < @eDate AND C.CORP=@CORP SELECT @l_error = @@error IF @l_error <> 0 BEGIN ROLLBACK TRAN tran_JZ RETURN 2 END IF EXISTS (SELECT 1 FROM #JZ_1 WHERE MD<>0) BEGIN INSERT INTO #JZ select * from #JZ_1 SELECT @l_error = @@error IF @l_error <> 0 BEGIN ROLLBACK TRAN tran_JZ RETURN 4 END END ---查询临时表#JZ select * from #JZ DROP TABLE #JZ_1 if @l_trancnt = 0 commit tran return 0 set nocount off |