Advertisement
Guest User

Untitled

a guest
Jul 9th, 2015
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 5.27 KB | None | 0 0
  1.    QR.SQL.Add('select n.node_name, '+
  2.    'count(case     when (date(s.shop_date)<"'+date2mysql(report_datestart.Text)+'" and status=2) or (date(s.shop_date)<"'+date2mysql(report_datestart.Text)+'" and status=4 and date(sell_date)>="'+date2mysql(report_datestart.Text)+'") then s.id end) as tot_cnt,'+
  3.    'round(sum(case when date(s.shop_date)<"'+date2mysql(report_datestart.Text)+'" and (status=2) or (date(s.shop_date)<"'+date2mysql(report_datestart.Text)+'" and status=4 and date(sell_date)>="'+date2mysql(report_datestart.Text)+'") then total_weight end),2) as tot_wt,'+
  4.    'sum(case       when date(s.shop_date)<"'+date2mysql(report_datestart.Text)+'" and (status=2) or (date(s.shop_date)<"'+date2mysql(report_datestart.Text)+'" and status=4 and date(sell_date)>="'+date2mysql(report_datestart.Text)+'") then kredit end) as tot_kr,'+
  5.    'sum(case       when date(s.shop_date)<"'+date2mysql(report_datestart.Text)+'" and (status=2) or (date(s.shop_date)<"'+date2mysql(report_datestart.Text)+'" and status=4 and date(sell_date)>="'+date2mysql(report_datestart.Text)+'") then price end) as tot_pr,'+
  6.  
  7.    'count(case when date(s.shop_date) between "'+date2mysql(report_datestart.Text)+'" and "'+date2mysql(report_dateend.Text)+'" and (status in(2,4)) then s.id end) as new_cnt,'+
  8.    'round(sum(case when date(s.shop_date) between "'+date2mysql(report_datestart.Text)+'" and "'+date2mysql(report_dateend.Text)+'" and (status in(2,4)) then total_weight end),2) as new_wt,'+
  9.    'sum(case when date(s.shop_date) between "'+date2mysql(report_datestart.Text)+'" and "'+date2mysql(report_dateend.Text)+'" and (status in(2,4)) then kredit end) as new_kr,'+
  10.    'sum(case when date(s.shop_date) between "'+date2mysql(report_datestart.Text)+'" and "'+date2mysql(report_dateend.Text)+'" and (status in(2,4)) then price end)as new_pr,'+
  11.  
  12.    'count(case when date(s.sell_date) between "'+date2mysql(report_datestart.Text)+'" and "'+date2mysql(report_dateend.Text)+'" and status=4 then s.id end) as sell_cnt,'+
  13.    'round(sum(case when date(s.sell_date) between "'+date2mysql(report_datestart.Text)+'" and "'+date2mysql(report_dateend.Text)+'" and status=4 then total_weight end),2) as sell_wt,'+
  14.    'sum(case when date(s.sell_date) between "'+date2mysql(report_datestart.Text)+'" and "'+date2mysql(report_dateend.Text)+'" and status=4 then kredit end) as sell_kr,'+
  15.    'sum(case when date(s.sell_date) between "'+date2mysql(report_datestart.Text)+'" and "'+date2mysql(report_dateend.Text)+'" and status=4 then vyruchka end) as sell_pr,'+
  16.    'sum(case when date(s.sell_date) between "'+date2mysql(report_datestart.Text)+'" and "'+date2mysql(report_dateend.Text)+'" and status=4 and price>vyruchka then price-vyruchka end) as sell_discount,'+
  17.  
  18.  
  19.    'count(case when store_num is not null and date(s.sell_date) between "'+date2mysql(report_datestart.Text)+'" and "'+date2mysql(report_dateend.Text)+'" and status=4 then s.id end) as sell_l_cnt,'+
  20.    'round(sum(case when store_num is not null and date(s.sell_date) between "'+date2mysql(report_datestart.Text)+'" and "'+date2mysql(report_dateend.Text)+'" and status=4 then total_weight end),2) as sell_l_wt,'+
  21.    'sum(case when store_num is not null and  date(s.sell_date) between "'+date2mysql(report_datestart.Text)+'" and "'+date2mysql(report_dateend.Text)+'" and status=4 then kredit end) as sell_l_kr,'+
  22.    'sum(case when store_num is not null and date(s.sell_date) between "'+date2mysql(report_datestart.Text)+'" and "'+date2mysql(report_dateend.Text)+'" and status=4 then vyruchka end) as sell_l_pr,'+
  23.  
  24.    'count(case when date(s.sell_date) between "'+date2mysql(report_datestart.Text)+'" and "'+date2mysql(report_dateend.Text)+'" and status=5 then s.id end) as ret_cnt,'+
  25.    'round(sum(case when date(s.sell_date) between "'+date2mysql(report_datestart.Text)+'" and "'+date2mysql(report_dateend.Text)+'" and status=5 then total_weight end),2) as ret_wt,'+
  26.    'sum(case when date(s.sell_date) between "'+date2mysql(report_datestart.Text)+'" and "'+date2mysql(report_dateend.Text)+'" and status=5 then kredit end) as ret_kr,'+
  27.    'sum(case when date(s.sell_date) between "'+date2mysql(report_datestart.Text)+'" and "'+date2mysql(report_dateend.Text)+'" and status=5 then price end) as ret_pr,'+
  28.  
  29.    'count(case when (status=2 and date(s.shop_date)<="'+date2mysql(report_dateend.Text)+'") or (date(s.shop_date)<="'+date2mysql(report_dateend.Text)+'" and status=4 and date(sell_date)>"'+date2mysql(report_dateend.Text)+'") then s.id end) as end_cnt,'+
  30.    'round(sum(case when (status=2  and date(s.shop_date)<="'+date2mysql(report_dateend.Text)+'") or (date(s.shop_date)<="'+date2mysql(report_dateend.Text)+'" and status=4 and date(sell_date)>"'+date2mysql(report_dateend.Text)+'") then total_weight end),2) as end_wt,'+
  31.    'sum(case when (status=2 and date(s.shop_date)<="'+date2mysql(report_dateend.Text)+'") or (date(s.shop_date)<="'+date2mysql(report_dateend.Text)+'" and status=4 and date(sell_date)>"'+date2mysql(report_dateend.Text)+'") then kredit end) as end_kr,'+
  32.    'sum(case when (status=2 and date(s.shop_date)<="'+date2mysql(report_dateend.Text)+'") or (date(s.shop_date)<="'+date2mysql(report_dateend.Text)+'" and status=4 and date(sell_date)>"'+date2mysql(report_dateend.Text)+'") then s.price end) as end_pr '+
  33.  
  34.      'from nodes n left join storage s  on n.Id=s.node_num group by s.node_num order by node_name'
  35.    );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement