主题:请教if语句的一个问题。
在MS SQL Server里的一个存储过程里写了这么一段:
declare @tmp table
(
a int IDENTITY (1, 1) NOT NULL,
b int,
c varchar(255),
d varchar(255)
)
if @t= '3' then
insert into @tmp(b, c ,d)
select b, c, d from t1 order by [datetime] desc
else
insert into @tmp(b, c ,d)
select b, c, d from t2 order by [datetime] desc
结果在then和else附近报错,这是什么原因呢?
declare @tmp table
(
a int IDENTITY (1, 1) NOT NULL,
b int,
c varchar(255),
d varchar(255)
)
if @t= '3' then
insert into @tmp(b, c ,d)
select b, c, d from t1 order by [datetime] desc
else
insert into @tmp(b, c ,d)
select b, c, d from t2 order by [datetime] desc
结果在then和else附近报错,这是什么原因呢?