Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Overiding a Null in a Sql statement using an aggregate function

Posted on 2013-11-04
4
Medium Priority
?
310 Views
Last Modified: 2013-11-04
Hi Everyone,

Is it possible to overide null statement in the following sql.  Note the field in SPCL_EARNS cannot contain a null value.


UPDATE X
 SET X.SPCL_EARNS =
(SELECT SUM(SPCL.SPCL_EARNS)
 FROM PS_CAAT_TMP TMP
 LEFT OUTER JOIN PS_SPCL_EARNS SPCL
 ON  SPCL.PAGE_NUM = TMP.PAGE_NUM
 AND SPCL.LINE_NUM = TMP.LINE_NUM
 AND SPCL.SEPCHK =   TMP.SEPCHK
 AND SPCL.OFF_CYCLE = TMP.OFF_CYCLE
 AND SPCL.PAY_END_DT = TMP.PAY_END_DT
 AND SPCL.EMPL_RCD = TMP.EMPL_RCD
 AND SPCL.PAYGROUP = TMP.PAYGROUP
 WHERE SPCL.PAY_END_DT >=  CASE WHEN X.MAX_PENS_EFFDT >= '01-01-2013' THEN  X.MAX_PENS_EFFDT ELSE  '01-01-2013' END
 AND SPCL.PAY_END_DT <= '03-23-2013'
 AND TMP.EMPLID = X.EMPLID
 AND TMP.EMPL_RCD = X.EMPL_RCD
 group by TMP.EMPLID, TMP.EMPL_RCD)
 )
 FROM PS_PY_CAAT_CALC  X


Any assistance would be greatly appreciated.   I don't know how to encase this statement in a case statement.

Thank you,
Nigluc
0
Comment
Question by:Lucia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 27

Accepted Solution

by:
Shaun Kline earned 2000 total points
ID: 39622108
You may be able to use the ISNULL function:

ISNULL((SELECT Statement), 0)
0
 
LVL 40

Expert Comment

by:lcohan
ID: 39622130
Would be something like in the query below:

UPDATE X
 SET X.SPCL_EARNS =
isnull(
(
SELECT SUM(SPCL.SPCL_EARNS)
 FROM PS_CAAT_TMP TMP
 LEFT OUTER JOIN PS_SPCL_EARNS SPCL
 ON  SPCL.PAGE_NUM = TMP.PAGE_NUM
 AND SPCL.LINE_NUM = TMP.LINE_NUM
 AND SPCL.SEPCHK =   TMP.SEPCHK
 AND SPCL.OFF_CYCLE = TMP.OFF_CYCLE
 AND SPCL.PAY_END_DT = TMP.PAY_END_DT
 AND SPCL.EMPL_RCD = TMP.EMPL_RCD
 AND SPCL.PAYGROUP = TMP.PAYGROUP
 WHERE SPCL.PAY_END_DT >=  CASE WHEN X.MAX_PENS_EFFDT >= '01-01-2013' THEN  X.MAX_PENS_EFFDT ELSE  '01-01-2013' END
 AND SPCL.PAY_END_DT <= '03-23-2013'
 AND TMP.EMPLID = X.EMPLID
 AND TMP.EMPL_RCD = X.EMPL_RCD
 group by TMP.EMPLID, TMP.EMPL_RCD
)
,0)

FROM PS_PY_CAAT_CALC X
0
 

Author Closing Comment

by:Lucia
ID: 39622136
You are great !

Thanks,
Nigluc
0
 

Author Comment

by:Lucia
ID: 39622137
Thanks everyone.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question