Foxtable(狐表)用户栏目专家坐堂 → [求助]SQL在fox中的实现


  共有2813人关注过本帖平板打印复制链接

主题:[求助]SQL在fox中的实现

帅哥哟,离线,有人找我吗?
jackwin
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:123 积分:943 威望:0 精华:0 注册:2013/7/25 14:52:00
[求助]SQL在fox中的实现  发帖心情 Post By:2014/6/19 14:50:00 [只看该作者]

各位

写了串sql查询 ,其中有两个变量:开始时期和结束日期。

问题:希望通过时间输入控件关联sql的变量实现查询

 

你把参数代入值,测试一下看看
select  '19000101' as 库存年月,
        'A010110010210201A0101-00102-0201' as 产品编码,
        '700103600000700103600000' as 南菲编码,
        '1111A' as 仓库编号,
        99999999.9999 as 单位成本,
        99999999.9999 as 本月销货数量,
        99999999.9999 as 本月销货金额
   into #a
insert into #a
EXEC zf_srv.fanski.dbo.[me_procGetMaterialCost] '01A',@开始日期,@结束日期
/*----++++*/
select left(CONVERT(varchar(100),w.c_au_dt,112),6) as 业务年月,
        bar.c_barcode as 主条码, 
  gds.c_name as 产品名称,  
        sum(isnull(c_number,0)+isnull(c_number_free,0))as 数量, 
  case when sum(isnull(#a.单位成本,0))=0 then sum(isnull(wg.c_pt_cost,0)/(isnull(wg.c_tax_rate,0)/100+1)*(isnull(wg.c_number,0)+isnull(wg.c_number_free,0)))
       else sum(isnull(#a.单位成本,0)*(isnull(c_number,0)+isnull(c_number_free,0))) end as  成本金额
   from tb_o_w w(nolock)
   left join tb_o_wg wg(nolock) on w.c_id=wg.c_id
   left join tb_gds gds(nolock) on wg.c_gcode=gds.c_gcode
   left join tb_barcode bar(nolock) on gds.c_gcode=bar.c_gcode
   left join tb_cust_orderg odg(nolock) on odg.c_id=wg.c_order_id and odg.c_gcode=wg.c_gcode and wg.c_in_guid=odg.c_guid
   left join tb_cust_order od(nolock) on odg.c_id=od.c_id
   left join #a on bar.c_barcode=#a.南菲编码 and left(CONVERT(varchar(100),w.c_au_dt,112),6)=#a.库存年月
  where (wg.c_number<>0 or wg.c_number_free<>0)
    and isnull(od.c_order_type,'')<>'物料订单'
    and w.c_status='已审核'
    and (isnull(@开始日期,'')='' or DATEDIFF(day,w.c_au_Dt,@开始日期)<=0)
    and (isnull(@结束日期,'')='' or DATEDIFF(day,w.c_au_Dt,@结束日期)>=0)
  group by bar.c_barcode,gds.c_name,left(CONVERT(varchar(100),w.c_au_dt,112),6)


 回到顶部