SQL语句问题,在线...
可参考http://expert.csdn.net/Expert/topic/2313/2313609.xml?temp=.7527124
不好意思,我将问题简化过度了,实际情况是这样的
CREATE PROCEDURE u_import_tritem
@dates datetime,
@datee datetime,
@movetype char(1), --in or out
@product char(1) --product or material
AS
select a.ref_no,a.move_date,a.tran_type,a.flow_type,a.move_type,a.issued_to,b.item_no,b.qty,
c.item_no,c.article_code,c.description
into #tt1
from icmovh a join icmovd b
on a.ref_no = b.ref_no join gbitem c on b.item_no = c.item_no
where a.move_date >= @dates and a.move_date <= @datee
and a.flow_type = ( case @product when 'A' then 'i' when 'B' then 'r'end )
and c.article_code is not null
and c.article_code <> ''
and a.posted = 'Y'
and a.move_type = ( case @product when 'B' then 'decin' or'bomrtn' when 'A' then 'decout'or mkout' or 'prdmsy'or 'prdout' end ) --就是这里错误
select * into #tt2 from dbo.trade e
where e.typeflag = @product
select a.ref_no,b.haiguanid,b.itemname,a.qty,c.oriprice,a.movedate,@movetype,@product
from #tt1 a join #tt2 b on a.article_code = b.article_code
当然还是那句case语句的问题。因为case在where 中所以楼上的部分方法用不上。因为a.move_type的值不子一个字符,所以大力的方法也用不上。aierong兄的应该可行,可不大方便,请兄台们想想如何很好解决。