declare @str varchar(20) set @str = 'A0'create table #Test(ph varchar(20),mq varchar(20)) insert into #Test (ph , mq) select ph , mq from aa where ISNUMERIC(@str) = 1 union all select ph , mq from bbb where ISNUMERIC(@str) <> 1
declare @str varchar(20) set @str = 'A0'create table #Test(ph varchar(20),mq varchar(20)) /*执行时提示 IF 附件有语法错误*/ if ISNUMERIC(@str) = 1 begin insert into #Test (ph , mq) select ph , mq from aa end elsebegin insert into #Test (ph , mq) select ph , mq from bbb end
但我直接这样写就可以:declare @wlph varchar(20) set @wlph = 'A0'if ISNUMERIC(@wlph) = 1 begin select ph , mq from aa end else begin select ph , mq from bbb end 改成如下就出错了:declare @wlph varchar(20) set @wlph = 'A0'create table #Test(ph varchar(20),mq varchar(20)) insert into #Test (ph , mq) /*提示 关键字 'if' 附近有语法错误。*/ if ISNUMERIC(@wlph) = 1 begin select ph , mq from aa end else begin select ph , mq from bbb end
insert into #Test (ph , mq) 目测这句有问题,请看看 PH,MQ 有没有问题.
insert into ... select ... 这个中间不能用if 如果用if的话,就是 if insert into ... select ... if insert into ... select ...不能 insert into ... if select ...
declare @str varchar(20) set @str = 'A0'create table #Test(ph varchar(20),mq varchar(20))
insert into #Test (ph , mq)
select ph , mq from aa where ISNUMERIC(@str) = 1
union all
select ph , mq from bbb where ISNUMERIC(@str) <> 1
set @str = 'A0'create table #Test(ph varchar(20),mq varchar(20)) /*执行时提示 IF 附件有语法错误*/
if ISNUMERIC(@str) = 1
begin
insert into #Test (ph , mq)
select ph , mq from aa
end
elsebegin
insert into #Test (ph , mq)
select ph , mq from bbb
end
set @wlph = 'A0'if ISNUMERIC(@wlph) = 1
begin
select ph , mq from aa
end
else
begin
select ph , mq from bbb
end
改成如下就出错了:declare @wlph varchar(20)
set @wlph = 'A0'create table #Test(ph varchar(20),mq varchar(20))
insert into #Test (ph , mq) /*提示 关键字 'if' 附近有语法错误。*/
if ISNUMERIC(@wlph) = 1
begin
select ph , mq from aa
end
else
begin
select ph , mq from bbb
end
insert into #Test (ph , mq) 目测这句有问题,请看看 PH,MQ 有没有问题.
如果用if的话,就是
if
insert into ... select ...
if
insert into ... select ...不能
insert into ...
if
select ...