×
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!
  • Students Click Here

*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.

Students Click Here

DB2 Sql help needed

DB2 Sql help needed

DB2 Sql help needed

(OP)
I have data which has 13 periods per year and ineach period there will be 4 weeks.Reports are generated for each week
with some amount fields corresponding to each week.
we also have week numbers which are integers from (1,2--52)
This amount field is for 1st week in each period is fine,for next week we need to subtract 2nd week amt from 1st week amt to get 2nd weeks amount, and similarly 3rd week amount from the 2nd week amount to get 3rd week amount and 4th week amount from 3rd week amt to get 4th weeks amount.

But when we go to second period we should not subtract the week 1 amount field from previous period's 4th week amount.
week 1 amount for period is fine,now we need to subtract 2nd week amt from 1st week amount.

I wrote sql statement as below

SELECT A.CUSTOMERNO, A.DATE, A.PERIOD,
( case when Mod(A.WEEKNO,4)= 0 then 4 Else Mod(A.WEEKNO,4) end),
A.ADDRESS, ( CASE WHEN (Mod(A.CAL_WEEK_ID,4)) = 1 Then A.GROCERY Else (A.AMT- B.AMT ) END )
FROM TABLEA A, TABLEB B
WHERE B.CUSTOMERNO = A.CUSTOMERNO year(B.DATE) = year(A.DATE) and
B.WEEKNO=A.WEEKNO-1 )

It is working fine for all the Periods from 2 to 13,but for the first period the week1 data is not displayed.

Do i need to change the SQL or do some additions to the above SQL.Please provide me the SQL for this problem.

Any help is appreciated.

Thanks

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! Already a Member? Login

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