大家帮帮忙 关于数据表与if else之间的问题,在线急等
storechain s ,
if '高库存 '= '高库存 '
begin
create table #ls_forWeekSaleQua(forWeekSaleQua int)
insert into #ls_forWeekSaleQua values (0)
select forWeekSaleQua from #ls_forWeekSaleQua
end
else
begin
(select orgno,merchid ,sum(SaleQuantity) as forWeekSaleQua
from MerchSaleHistory where historydate between '2006-2-15 ' and '2006-03-15 '
group by orgno,merchid)m
end
storechain 是一个数据库表,MerchSaleHistory 也是一个数据库表,
现在我执行整个SQL语句报
服务器: 消息 156,级别 15,状态 1,行 33
在关键字 'if ' 附近有语法错误。
而且还提示那个别名m报错,
大家帮帮忙,
------解决方案--------------------(select orgno,merchid ,sum(SaleQuantity) as forWeekSaleQua
from MerchSaleHistory where historydate between '2006-2-15 ' and '2006-03-15 '
group by orgno,merchid)m
------------------------------------------------------
改为:(去掉子查询括号和m)
select orgno,merchid ,sum(SaleQuantity) as forWeekSaleQua
from MerchSaleHistory where historydate between '2006-2-15 ' and '2006-03-15 '
group by orgno,merchid
------解决方案--------------------storechain s , --这样的语法是错误的
if '高库存 '= '高库存 ' --这个条件永远成立啊
begin
create table #ls_forWeekSaleQua(forWeekSaleQua int)
insert into #ls_forWeekSaleQua values (0)
select forWeekSaleQua from #ls_forWeekSaleQua
end
else
begin
select orgno,merchid ,sum(SaleQuantity) as forWeekSaleQua
from MerchSaleHistory where historydate between '2006-2-15 ' and '2006-03-15 '
group by orgno,merchid
end
------解决方案----------------------storechain s ,
if '高库存 '= '高库存 '
begin
create table #ls_forWeekSaleQua(forWeekSaleQua int)
insert into #ls_forWeekSaleQua values (0)
select forWeekSaleQua from #ls_forWeekSaleQua
end
else
begin
(select orgno,merchid ,sum(SaleQuantity) as forWeekSaleQua
from MerchSaleHistory where historydate between '2006-2-15 ' and '2006-03-15 '
group by orgno,merchid)
end
------解决方案--------------------把
(if '高库存 '= '高库存 '
...
else
...)
前后的括号去掉.即:
if '高库存 '= '高库存 '
...
else
...
------解决方案--------------------你那样加别名是不符合语法的,应该这样加别名(大写的部分):
if '高库存 '= '高库存 '
begin
create table #ls_forWeekSaleQua(forWeekSaleQua int)
insert into #ls_forWeekSaleQua values (0)
SELECT * FROM
(select forWeekSaleQua from #ls_forWeekSaleQua ) AS m
end
else
begin
SELECT * FROM
(select orgno,merchid ,sum(SaleQuantity) as forWeekSaleQua
from MerchSaleHistory where historydate between '2006-2-15 ' and '2006-03-15 '
group by orgno,merchid) AS m
end
------解决方案--------------------copy错了,不好意思:
select b.orgno,b.deptcode,b.sku,b.merchid,
c.merchname,isnull(c.packingname, ' ')packingname,