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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sql statement error when trying to substract

Status
Not open for further replies.

evr72

MIS
Dec 8, 2009
265
US
hello,

I have the SQL statement below, I am tryig to substract the value of the following fields INCHRBRKTOT - TOTHRS

This is my sql statement
Code:
SELECT
DAVLOGIC.MOROUTX4.DPTNO,
COUNT(DAVLOGIC.MOMASTX4.ORDNO) AS COUNTORDNO,
SUM(DAVLOGIC.MOMASTX4.HRREM) AS SUMHRREM,
DAVLOGIC.SCHHDCNT.HRSCHOVR,
(DAVLOGIC.SCHHDCNT.HRSCHOVR * COUNT(DAVLOGIC.MOMASTX4.ORDNO))+ SUM(DAVLOGIC.MOMASTX4.HRREM) AS TOTHRS,
(((MOND*WEEK1DYS*WEEK1HPD)*DPTEFF) *DAVLOGIC.SCHWKSPLT.BRKTM) AS INCHRBRK1,
(((TUESD * WEEK2DYS * WEEK2HPD)*DPTEFF) *DAVLOGIC.SCHWKSPLT.BRKTM) AS INCHRBRK2,
(((WEDN*
WEEK3DYS*
WEEK3HPD)*DPTEFF) *DAVLOGIC.SCHWKSPLT.BRKTM) AS INCHRBRK3,
(((THURSD*
WEEK4DYS*
WEEK4HPD)*DPTEFF) *DAVLOGIC.SCHWKSPLT.BRKTM) AS INCHRBRK4,
((((FRID*WEEK5DYS*WEEK5HPD)+(SATURD*WEEK5DYS*WEEK5HPD))*DPTEFF) *DAVLOGIC.SCHWKSPLT.BRKTM) AS INCHRBRK5,
((((MOND*WEEK1DYS*WEEK1HPD)*DPTEFF) *DAVLOGIC.SCHWKSPLT.BRKTM)+
(((TUESD * WEEK2DYS * WEEK2HPD)*DPTEFF) *DAVLOGIC.SCHWKSPLT.BRKTM)+
(((WEDN*
WEEK3DYS*
WEEK3HPD)*DPTEFF) *DAVLOGIC.SCHWKSPLT.BRKTM)+
(((THURSD*
WEEK4DYS*
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*DPTEFF) *DAVLOGIC.SCHWKSPLT.BRKTM)+
((((FRID*WEEK5DYS*WEEK5HPD)+(SATURD*WEEK5DYS*WEEK5HPD))*DPTEFF) *DAVLOGIC.SCHWKSPLT.BRKTM))
ORDER BY DAVLOGIC.MOROUTX4.DPTNO


This is what I am adding
Code:
(((((MOND*WEEK1DYS*WEEK1HPD)*DPTEFF) *DAVLOGIC.SCHWKSPLT.BRKTM)+
(((TUESD * WEEK2DYS * WEEK2HPD)*DPTEFF) *DAVLOGIC.SCHWKSPLT.BRKTM)+
(((WEDN*WEEK3DYS*WEEK3HPD)*DPTEFF) *DAVLOGIC.SCHWKSPLT.BRKTM)+
(((THURSD*WEEK4DYS*WEEK4HPD)*DPTEFF) *DAVLOGIC.SCHWKSPLT.BRKTM)+
((((FRID*WEEK5DYS*WEEK5HPD)+(SATURD*WEEK5DYS*WEEK5HPD))*DPTEFF) *DAVLOGIC.SCHWKSPLT.BRKTM)) - 
(DAVLOGIC.SCHHDCNT.HRSCHOVR * COUNT(DAVLOGIC.MOMASTX4.ORDNO))+ SUM(DAVLOGIC.MOMASTX4.HRREM))


I get the following error
Code:
SQL Error State:HY000, Native error Code: FFFFFF86, ODBC Error: IBM iSeries Access ODBC driver DB2 UDB SQL0122 - Column MOND or excression in select list not valid

not if I add each one of the above statements it woks but if I try to subtract I get the error

Any help is much appreciated.

Thanks in advance
 
when I group it i get SQL012- Use of finction COUONT not valid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top