Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Need4Speed
Message
From
02/12/2016 12:43:26
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Need4Speed
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows 7
Network:
Windows XP
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01644268
Message ID:
01644268
Views:
78
Dear Experts,
I am using these codes.
The codes work fine, no issue.

Is it possible to make the code shorten for speed?
SELECT distinct(LEFT(data.acc_code,4)) as acc_code,
sum(isnull(data.dr_amount,0))as dr_amount1,
sum(isnull(data.cr_amount,0))as  cr_amount1,
(case when sum(isnull(data.dr_amount,0)) + sum(isnull(data.cr_amount,0))>0  then sum(isnull(data.dr_amount,0)) + sum(isnull(data.cr_amount,0)) end) as dr_amount,
(case when sum(isnull(data.dr_amount,0)) + sum(isnull(data.cr_amount,0))<0  then sum(isnull(data.cr_amount,0)) + sum(isnull(data.dr_amount,0)) end) as cr_amount
   from (
SELECT max(acc_code)as acc_code,
(case when sum(open_dr) > sum(open_cr)  then sum(open_dr) - sum(open_cr) end) as dr_amount,
(case when sum(open_dr) < sum(open_cr)  then sum(open_dr) - sum(open_cr) end) as cr_amount
 from master where  len(acc_code)=7 group by left(acc_code,4)
union all
SELECT max(acc_code)as acc_code, 
(case when sum(dr_amount) > sum(cr_amount)  then sum(dr_amount) - sum(cr_amount) end) as dr_amount,
(case when sum(dr_amount) < sum(cr_amount)  then sum(dr_amount) - sum(cr_amount) end) as cr_amount
 from vouchers  where  date <=   '".$t_date1 ."' and  len(acc_code)=7 group by left(acc_code,4)
union all
SELECT max(acc_code)as acc_code, 
(case when sum(dr_amount) > sum(cr_amount)  then sum(dr_amount) - sum(cr_amount) end) as dr_amount,
(case when sum(dr_amount) < sum(cr_amount)  then sum(dr_amount) - sum(cr_amount) end) as cr_amount
  from cashsalp   where  date <=   '".$t_date1 ."' and  len(acc_code)=7 group by left(acc_code,4)
union all
SELECT max(acc_code)as acc_code,
(case when sum(dr_amount) > sum(cr_amount)  then sum(dr_amount) - sum(cr_amount) end) as dr_amount,
(case when sum(dr_amount) < sum(cr_amount)  then sum(dr_amount) - sum(cr_amount) end) as cr_amount
  from crsalp    where  date <=   '".$t_date1 ."' and  len(acc_code)=7 group by left(acc_code,4)
union all
SELECT max(acc_code)as acc_code, (case when sum(dr_amount) > sum(cr_amount)  then sum(dr_amount) - sum(cr_amount) end) as dr_amount,
(case when sum(dr_amount) < sum(cr_amount)  then sum(dr_amount) - sum(cr_amount) end) as cr_amount
  from brsalp  where  date <=   '".$t_date1 ."' and  len(acc_code)=7 group by left(acc_code,4)
union all
SELECT max(acc_code)as acc_code, (case when sum(dr_amount) > sum(cr_amount)  then sum(dr_amount) - sum(cr_amount) end) as dr_amount,
(case when sum(dr_amount) < sum(cr_amount)  then sum(dr_amount) - sum(cr_amount) end) as cr_amount
  from mrsalp    where  date <=   '".$t_date1 ."' and  len(acc_code)=7 group by left(acc_code,4)
union all
SELECT max(acc_code)as acc_code, (case when sum(dr_amount) > sum(cr_amount)  then sum(dr_amount) - sum(cr_amount) end) as dr_amount,
(case when sum(dr_amount) < sum(cr_amount)  then sum(dr_amount) - sum(cr_amount) end) as cr_amount
  from orsalp     where  date <=   '".$t_date1 ."' and  len(acc_code)=7 group by left(acc_code,4)
union all
SELECT max(acc_code)as acc_code,  (case when sum(dr_amount) > sum(cr_amount)  then sum(dr_amount) - sum(cr_amount) end) as dr_amount,
(case when sum(dr_amount) < sum(cr_amount)  then sum(dr_amount) - sum(cr_amount) end) as cr_amount
  from frsalp  where  date <=   '".$t_date1 ."' and  len(acc_code)=7 group by left(acc_code,4)
union all
SELECT max(acc_code)as acc_code,  (case when sum(dr_amount) > sum(cr_amount)  then sum(dr_amount) - sum(cr_amount) end) as dr_amount,
(case when sum(dr_amount) < sum(cr_amount)  then sum(dr_amount) - sum(cr_amount) end) as cr_amount
  from Srsalp    where  date <=   '".$t_date1 ."' and  len(acc_code)=7 group by left(acc_code,4)
union all
SELECT max(acc_code)as acc_code, (case when sum(dr_amount) > sum(cr_amount)  then sum(dr_amount) - sum(cr_amount) end) as dr_amount,
(case when sum(dr_amount) < sum(cr_amount)  then sum(dr_amount) - sum(cr_amount) end) as cr_amount
  from cashprp   where  date <=   '".$t_date1 ."' and  len(acc_code)=7 group by left(acc_code,4)
union all
SELECT max(acc_code)as acc_code, (case when sum(dr_amount) > sum(cr_amount)  then sum(dr_amount) - sum(cr_amount) end) as dr_amount,
(case when sum(dr_amount) < sum(cr_amount)  then sum(dr_amount) - sum(cr_amount) end) as cr_amount
  from crprp    where  date <=   '".$t_date1 ."' and  len(acc_code)=7 group by left(acc_code,4))
 as data
where  len(acc_code)=7
group by left(acc_code,4)
Next
Reply
Map
View

Click here to load this message in the networking platform