日期:2014-05-16 浏览次数:20690 次
Declare @OrderNoList Varchar(500)
Set @OrderNoList='''136987A'''
Declare @Sqlx Varchar(8000)
Set @Sqlx='select top 10
SubString(b.cust_so_ref,1,Charindex(''-'',b.cust_so_ref)-1) OrderNo,
ISNULL(RTRIM(c.description), '''') AS CheckPointDesc,Sum(a.qty) Qty
from
Arfid_transaction_table a inner join Asp_ord_master b on b.key_seq=a.jo_key_seq and b.status in (1, 2)
inner join Ajo_step c on c.link_key_seq=a.jo_key_seq and c.major_step=a.major and c.component=a.component
inner join Aemployee d on a.employee_id=d.emp_no
inner join Ajo_finished_goods e on e.key_seq=a.jo_sku_key_seq
where
a.major=''276'' and SubString(b.cust_so_ref,1,Charindex(''-'',b.cust_so_ref)-1) in ('+@OrderNoList+')
Group by
b.cust_so_ref,c.description'
Exec(@Sqlx)
Declare @OrderNoList Varchar(500)
Set @OrderNoList='''136987A'''
Declare @Sqlx Varchar(8000)
Set @Sqlx='select top 10
SubString(b.cust_so_ref,1,Charindex(''-'',b.cust_so_ref)-1) OrderNo,
ISNULL(RTRIM(c.description), '''') AS CheckPointDesc,Sum(a.qty) Qty
from
Arfid_transaction_table a inner join Asp_ord_master b on b.key_seq=a.jo_key_seq and b.status in (1, 2)
inner join Ajo_step c on c.link_key_seq=a.jo_key_seq and c.major_step=a.major and c.component=a.component
inner join Aemployee d on a.employee_id=d.emp_no
inner join Ajo_finished_goods e on e.key_seq=a.jo_sku_key_seq
where
a.major=''276''
Group by
b.cust_so_ref,c.description'
Exec(@Sqlx)
两处的(SELECT 中的及WHERE 中的)
SubString(b.cust_so_ref,1,Charindex(''-'',b.cust_so_ref)-1)
改为
CASE WHEN Charindex(''-'',b.cust_so_ref)>0 THEN SubString(b.cust_so_ref,1,Charindex(''-'',b.cust_so_ref)-1) ELSE b.cust_so_ref END