当前位置: 代码迷 >> Sql Server >> 此语句能优化吗?解决办法
  详细解决方案

此语句能优化吗?解决办法

热度:151   发布时间:2016-04-27 19:43:02.0
此语句能优化吗?
insert   into   yfcc(票号,序号,小号,产品编号,库房,批号,效期,标识,库房数量,数量,件数,保管员,审核时间,业务1,业务2,业务3,业务4,业务5,单价,金额)   select   top   1   @p,@x, '1 ',kc.产品编号,库房,批号,效期,标识,库房数量,(case   when     库房= 'dk1 '     then   (case   when   kc.产品编号   in(select   产品编号   from   cp   where   功效   like   'A% ')   then   cp.包装   else   round(cp.包装/2,0)   end)   else   (case   when   kc.产品编号   in(select   产品编号   from   cp   where   功效   like   'A% ')   then   cp.包装*2   else   cp.包装   end)   end), '1 ',@kh1,getdate(), ' ', ' ', ' ', ' ', ' ',round(cp.平均进价,2),round(round(cp.平均进价,2)*(case   when     库房= 'dk1 '     then   (case   when   kc.产品编号   in(select   产品编号   from   cp   where   功效   like   'A% ')   then   cp.包装   else   round(cp.包装/2,0)   end)   else   (case   when   kc.产品编号   in(select   产品编号   from   cp   where   产品编号=kc.产品编号   and   功效   like   'A% ')   then   cp.包装*2   else   cp.包装   end)   end),2)   from   kc   inner   join   cp   on   cp.产品编号=kc.产品编号   and   (select   客户全称   from   kh   where   [email protected])   like   left(cp.产地,5)+ '% '   and   (left(批号,6)   between   substring(convert(varchar(8),cast(convert(varchar,(@[email protected]),112)   as   datetime)-30*cast(6+rand()*(9-6)   as   int),112),3,6)   and   substring(convert(varchar(8),cast(convert(varchar,(@[email protected]),112)   as   datetime)-5,112),3,6))   and   cast(convert(varchar,(@[email protected]),112)   as   datetime) <效期   and   kc.产品编号   not   in(select   产品编号   from   yfcc   where   [email protected]   and   substring(票号,5,8)=left(convert(char,(@[email protected]),112),8))     order   by   newid()


------解决方案--------------------
in(select 产品编号 from cp where 功效 like 'A% ')
------------------------
三个一样,另一个类似,多加个条件而已

declare @temp table (产品编号 ???)
insert @temp select 产品编号 from cp where 功效 like 'A% '

try:[email protected]
  相关解决方案