Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Aliases for fields 1

Status
Not open for further replies.

evr72

MIS
Dec 8, 2009
265
US
Hello,

kind of new to DB2 SQL

I am trying to write a simple query but have a bunch of errors when do a "Where Statement"
so I was thinking in doing aliases for the fields but that does not seem to work,

Here is a snipet of my query

Code:
SELECT

DAVLOGIC.MOMASTLF.ORDNO,

EDGARQRY.MOIP.ITNBR,

EDGARQRY.MOIP.TRQTY01,

DAVLOGIC.MOROUTX3.OPSEQ,

DAVLOGIC.MOROUTX3.TQCTD,

EDGARQRY.COMPPRDREW.LTRQTY01,

EDGARQRY.COMPPRDREW.LRWKQT01,

DAVLOGIC.MOMASTLF.ORQTY,

DAVLOGIC.MOMASTLF.QTDEV,

Case when DAVLOGIC.MOMASTLF.OSTAT='45' then 'Closed' else 'Open' end AS Status,

DAVLOGIC.MOROUTX3.DPTNO,

DAVLOGIC.MOMASTLF.FITEM,

DAVLOGIC.MOMASTLF.FDESC,

DAVLOGIC.MOMASTLF.QTYRC,

DAVLOGIC.MOROUTX3.TQCTD - DAVLOGIC.MOMASTLF.QTYRC AS Difference,

DAVLOGIC.MOROUTX3.OPDSC,

DAVLOGIC.MOROUTX3.TQCTD + EDGARQRY.COMPPRDREW.LRWKQT01 + DAVLOGIC.MOROUTX3.SCRAP AS MoldPlusReworkScrp,

DAVLOGIC.MOROUTX3.SCRAP,

DAVLOGIC.MOMASTLF.QTYRC - EDGARQRY.MOIP.TRQTY01 AS InsrtvsQtyRc,

(DAVLOGIC.MOMASTLF.QTYRC - EDGARQRY.MOIP.TRQTY01)/EDGARQRY.MOIP.TRQTY01 AS prcntdiff,

DAVLOGIC.MOMASTLF.ASTDT

FROM DAVLOGIC.MOMASTLF

LEFT OUTER JOIN EDGARQRY.MOIP ON DAVLOGIC.MOMASTLF.ORDNO = EDGARQRY.MOIP.ORDNO

LEFT OUTER JOIN DAVLOGIC.MOROUTX3 ON EDGARQRY.MOIP.ORDNO = DAVLOGIC.MOROUTX3.ORDNO

LEFT OUTER JOIN EDGARQRY.COMPPRDREW ON DAVLOGIC.MOROUTX3.ORDNO = EDGARQRY.COMPPRDREW.LORD AND DAVLOGIC.MOROUTX3.OPSEQ = EDGARQRY.COMPPRDREW.LOPSEQ

The code above works well but when I try this

Code:
Where DAVLOGIC.MOMASTLF.QTYRC - EDGARQRY.MOIP.TRQTY01 / DAVLOGIC.MOMASTLF.QTYRC >.05

it does not work so I was since I have the
Code:
(DAVLOGIC.MOMASTLF.QTYRC - EDGARQRY.MOIP.TRQTY01)/EDGARQRY.MOIP.TRQTY01 AS prcntdiff
in the select statement I wanted to do this

Code:
(DAVLOGIC.MOMASTLF.QTYRC - EDGARQRY.MOIP.TRQTY01)/EDGARQRY.MOIP.TRQTY01 AS prcntdiff,
prcntdiff
FROM DAVLOGIC.MOMASTLF

LEFT OUTER JOIN EDGARQRY.MOIP ON DAVLOGIC.MOMASTLF.ORDNO = EDGARQRY.MOIP.ORDNO

LEFT OUTER JOIN DAVLOGIC.MOROUTX3 ON EDGARQRY.MOIP.ORDNO = DAVLOGIC.MOROUTX3.ORDNO

LEFT OUTER JOIN EDGARQRY.COMPPRDREW ON DAVLOGIC.MOROUTX3.ORDNO = EDGARQRY.COMPPRDREW.LORD AND DAVLOGIC.MOROUTX3.OPSEQ = EDGARQRY.COMPPRDREW.LOPSEQ
Where prcntdiff > .05
but that did not work either

any help is appreciated!!!
 
What sqlcode(s) are beng raised?

it does not work so I was since I have the
This provides nothing for us to use to help you.


Have you talked with your dba or some senior on your project? If not, this would be a good thing to do now (actually it would have been better to ask them first). In addition to getting the process to work, you may need to consider your local standards.


 
Try this syntax
Code:
select * 
from table ( select empno     as xx
                  , salary    as monthly_insult
                  , bonus     as robbed_by_banker
             from   employee 
           ) a
where a.monthly_insult + a.robbed_by_banker > 10000
 
Or in other words, look up what 'inline views' can do for you :)

Ties Blom

 
We can all suggest differing ways to do this, but looking at the original code (not the "Where prcntdiff > .05" bit), I can't see any reason why "it does not work".

I think papadba has hit the nail on the head and we need a bit more information before we can help out any further. "it does not work" might mean "it didn't return the data I was expecting" for all we know.

evr72, care to come back to us and comment?
 
sorry about that I was out for a while.

as it turns out it looks like it was a coding error. did a debug and was able to run the code as I originally posted. I appreciate all the suggetions.

Thank you!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top