Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8515815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:15:01+00:00 2026-06-11T05:15:01+00:00

Got some help the other day on this and now really want to make

  • 0

Got some help the other day on this and now really want to make a change for the better

Here is code

select 
    machines.serialnum, DRPS.assetnumber, DRPS.MOCALCSUM, DRPS.MICALCSUM,
    DRPS.COCALCSUM, DRPS.CICALCSUM, ISSUED.TotalIssued,
    REDEEMED.TotalRedeemed,drps.dropdate1,drps.dropdate2
from
    (select serialnum
     from machineinfo) as machines
LEFT JOIN 
    (select 
        assetnumber, min(dropdate) as [dropdate1], max(dropdate) as [dropdate2], 
        sum(mocalc) AS [MOCALCSUM], sum(micalc) AS [MICALCSUM],
        sum(cocalc) AS [COCALCSUM],sum(cicalc) AS [CICALCSUM]
     from drops
     where dropdate > '09/04/2012' and dropdate < dateadd(hour, -0, getdate())
     GROUP BY assetnumber) AS DRPS on machines.serialnum = drps.assetnumber
LEFT JOIN 
    (select 
        snissued, cast(sum(amount) as money) / 100 AS [TotalIssued] 
     from tickets
     where  dateissued > '09/04/2012' and dateissued < dateadd(hour, 0, getdate())
     group by snissued) AS ISSUED ON machines.serialnum = ISSUED.snissued
LEFT JOIN 
    (select 
         snredeemed, cast(sum(amount) as money) / 100 AS [TotalRedeemed] 
     from tickets
     where  dateredeemed > '09/04/2012' and dateredeemed < dateadd(hour, 0, getdate())
     group by snredeemed) AS REDEEMED ON machines.serialnum = REDEEMED.snredeemed

what I would like to accomplish if possible is for the second and third join is to use the drps.drop1 in the where clause like this

where  dropdate > drps.dropdate1 and dropdate < drps.dropdate2

but it does not work

here is working output

    serialnum   MOCALCSUM   MICALCSUM   COCALCSUM   CICALCSUM   TotalIssued TotalRedeemed   dropdate1   dropdate2
0-2739-41401    5482    5498    132 148 3258.00 3110.00 2012-09-04 13:36:53.450 2012-09-05 13:55:38.750
0-2459-36182    1110    1054    114 58  1895.00 1657.00 2012-09-04 15:01:19.973 2012-09-05 13:55:38.967

end result is I need total issued and total redeemed date range to be between the min and max date per serial number

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T05:15:02+00:00Added an answer on June 11, 2026 at 5:15 am
    declare @datebegin datetime
    declare @dateend datetime
    set @datebegin = '09/04/2012'
    set @dateend = '09/08/2012'
    
    select machines.serialnum,     DRPS.MOCALCSUM,DRPS.MICALCSUM,DRPS.COCALCSUM,DRPS.CICALCSUM,ISSUED.TotalIssued,
            REDEEMED.TotalRedeemed,drps.dropdate1,drps.dropdate2
    
    from (select serialnum
        from machineinfo) as machines
    
    
    LEFT JOIN (select assetnumber,min(dropdate)as [dropdate1], max(dropdate)as [dropdate2], sum(mocalc) AS [MOCALCSUM],sum(micalc) AS [MICALCSUM],
        sum(cocalc) AS [COCALCSUM],sum(cicalc) AS [CICALCSUM]
        from drops
        where  dropdate > @datebegin and dropdate < @dateend AND  (ignore is null)
                group by assetnumber) AS DRPS
        on machines.serialnum = drps.assetnumber
    LEFT JOIN (select snissued,cast(sum(amount)as money)/100 AS [TotalIssued] from tickets
    where  (dateissued > (select min(dropdate)
                            from drops 
                            where dropdate > @datebegin AND  (ignore is null) and snissued = assetnumber ))
                            and
           (dateissued < (select max(dropdate)
                            from drops 
                            where dropdate < @dateend AND  (ignore is null) and snissued = assetnumber))
    group by snissued) AS ISSUED
    ON machines.serialnum=ISSUED.snissued
    LEFT JOIN (select snredeemed,cast(sum(amount)as money)/100 AS [TotalRedeemed]
    
    from tickets
    where  (dateredeemed > (select min(dropdate)
                            from drops 
                            where dropdate > @datebegin AND  (ignore is null)and snissued = assetnumber))
                            and
           (dateredeemed < (select max(dropdate)
                            from drops 
                            where dropdate < @dateend AND  (ignore is null)and snissued = assetnumber ))
    
    group by snredeemed) AS REDEEMED
    ON machines.serialnum=REDEEMED.snredeemed
    order by REDEEMED.TotalRedeemed desc
    

    based on the suggestion from comments i added the subquery into the selects and i am getting expected results now

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got some code off the Internet and now I just need help to
I need some help. I've got some php code which I want on every
Got some code that is not mine and its producing this warning atm: iehtmlwin.cpp(264)
So, I need some code help. I've got an awkward little MySQL table that
I need some help figuring out how to do something. I got this gallery
I was hoping for some help on this as I'm really stuck after trying
When I want to install VS2010 Ultimate , I got some errors like this
Thanks to some help I received yesterday I've got some dynamic summing working on
Recently I got some help with grouping when a user enters a null value
i got some problem and need help .. my plan : 1. get ip

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.