34,587
社区成员
发帖
与我相关
我的任务
分享
if 'a'='b'
begin
DECLARE @t TABLE(i int)
insert into @t
select 1
create table #t(j int)
insert into #t
select 2
end
SELECT *
FROM @t
--输出空行
select *
from #t
--报错
if 1=2
declare @i int
else
set @i=1
select @i
--1
declare @i int
select @i=1
while @i<4
begin
declare @j int
select @j=ISNULL(@j+1,1)
select @i=@i+1
end
select @i,@J
--4 3
DECLARE @t TABLE(i int)
if 'a'='b'
begin
insert into @t
select 1
create table #t(j int)
insert into #t
select 2
end
SELECT *
FROM @t
--输出空行
select *
from #t
--报错
declare @i int
if 1=2
PRINT '什么也不做,但不写点东西语句会报错'
else
set @i=1
select @i
--1
declare @i int
select @i=1
declare @j int
while @i<4
begin
select @j=ISNULL(@j+1,1)
select @i=@i+1
end
select @i,@J
--4 3
if 1=2
select @i=1
else
declare @i
這樣不行,是因為 declare @i 不是在 IF 這一個區塊內 的原因嗎?
謝謝!