2

我拥有的这个功能可以满足我的需求,但只是想知道是否有办法一次性完成:

drop table ##aa
select s.storeid,cast(LEFT(p.paytype,1) as varchar(50)) as Paytype,SUM(amount) as Total
into ##aa
from RPTrs s, rpPay p
where s.storeid=p.StoreID and s.ReceiptNO=p.ReceiptNo 
and trsdate between '1/1/06' and '1/1/13'
group by s.storeid,LEFT(p.paytype,1)

update A set a.paytype=b.currencydesc
from ##aa a, Currencies b
where a.Paytype=b.POSCurrency

select * from ##aa order by Paytype, StoreID

我要问的是,我想将 b.CurrencyDesc 应用于初始 p.paytype。Paytype 仅显示 C 作为示例,但我希望它代表现金,V 代表 Visa,如货币表中所述

4

1 回答 1

1

好像你可以添加一个JOIN

select   s.storeid
       , b.currencydesc as Paytype
       , SUM(amount)    as Total
into     ##aa
from     RPTrs s

join     rpPay p
on       s.storeid=p.StoreID
     and s.ReceiptNO=p.ReceiptNo

join     Currencies b 
on       b.POSCurrency=cast(LEFT(p.paytype,1) as varchar(50))

where    trsdate between '1/1/06' and '1/1/13'
group by s.storeid
       , b.currencydesc

转换为使用显式连接语法。不知道什么表有贡献trsdate。而且我不确定CAST加入条件是否需要。

于 2013-01-31T23:21:16.040 回答