Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Tuning SQL Query

$
0
0

Hi All,

Any suggestions/recommendations on tuning this query ?

select distinct 
          tbl1.NUMBR,
          tbl2.LCLTY ,
          tbl2.NPIN, 
          tbl2.PINN
    from
         dbo.LINE as tbl2,
         dbo.FACT as tbl1,
          (select distinct  P_NPIN, P_PINN
                                from ST.FACT hdr,
                                    ST.HIST hist,
                                     ST.LINE
                                where   hdr.TYPECD = 'APPLE' and
                                                hdr.active_status = 'Y' and           
                                                hdr.CCD  = hist.C_NUM and
                                                hist.rrtype in ('T','F') and
                                                hist.active_status = 'Y' and
                                                line.C_KEY = hdr.C_KEY and
                                                line.LN_KEY = 1) as tbl5
    where  
        tbl2.C_KEY = tbl1.C_KEY  and
        tbl2.CD_LN_KEY = 1 and
        tbl2.NPIN = tbl5.P_NPIN   and
        substring(tbl2.PINN,1,9)  = tbl5.P_PINN
        and
                tbl1.C_KEY =
            (select max(tbl3b.C_KEY) from  
                dbo.LINE as tbl4a,
                dbo.FACT as tbl3b
             where
                 tbl4a.C_KEY = tbl3b.C_KEY  and
                 tbl4a.CD_LN_KEY = 1 and
                 tbl4a.NPIN = tbl2.NPIN and
                 tbl4a.PINN = tbl2.PINN and
                 tbl3b.C_DATE in
                  (select max(C_DATE)
                      from 
                       dbo.LINE as tbl4,
                       dbo.FACT as tbl3
                      where
                       tbl4.C_KEY = tbl3.C_KEY  and
                       tbl4.CD_LN_KEY = 1 AND 
                       tbl4.NPIN =  tbl2.NPIN  AND
                       tbl4.PINN =  tbl2.PINN)
                                )


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>