INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Aliases for fields

Aliases for fields

(OP)
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!!!

RE: Aliases for fields

What sqlcode(s) are beng raised?

Quote:

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.


 

RE: Aliases for fields

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

RE: Aliases for fields

Or in other words, look up what 'inline views' can do for you  :)

Ties Blom
 
 

RE: Aliases for fields

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?

RE: Aliases for fields

(OP)
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!!!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close