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 5978507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:31:32+00:00 2026-05-22T21:31:32+00:00

Okay, so I am trying to get a given output in SQL to list

  • 0

Okay, so I am trying to get a given output in SQL to list a custom quarter value along with an accounts given activation and termination date. My company uses an off-standard quarter reckoning so I created a little schema matching the custom quarter recognition to standard months. The query works great until i try to get the thing to also include the termination quarter as well.

I am going to use this as a view and generate a report from its results. Here is the query thus far. I recognize that I am not very good SQL yet so i am trying hard to use best practices and easily readable code. Please feel free to critique anything at all or perhaps suggest a more efficient way of achieving my goal.

SELECT ZoneA.ZoneDescription
        ,TrackerA.Zone
        ,MasterListA.Name
        ,SubscriptionsA.ActivationDate
        ,SubscriptionsA.TerminationDate
        ,ParentA.ProductParentType
        ,MONTH(SubscriptionsA.ActivationDate) AS ActivationMonth
        ,MONTH(SubscriptionsA.TerminationDate) AS TerminationMonth
        ,QuartersA.CompanyFiscalQuarter AS ActivationQuarter
        ,QuartersB.CompanyFiscalQuarter AS TerminationQuarter
FROM BalanceTracker.Zone AS ZoneA INNER JOIN
        BalanceTracker.TrackerAccounts AS TrackerA ON ZoneA.ZoneID = TrackerA.Zone INNER JOIN
        BalanceTracker.SweepAccounts AS SweepA ON TrackerA.TrackedAccount = SweepA.SweepAccount INNER JOIN
        Fed.MasterAccountList AS MasterListA ON SweepA.MasterAccountListID = MasterListA.MasterAccountListID INNER JOIN
        Products.Subscriptions AS SubscriptionsA ON MasterListA.MasterAccountListID = SubscriptionsA.SnlId INNER JOIN
        Products.ProductParent AS ParentA ON SubscriptionsA.ProductCode = ParentA.ProductCode INNER JOIN
        Calendar.Quarters AS QuartersA ON SubscriptionsA.ActivationMonth = QuartersA.MonthNumber,
        Products.Subscriptions AS SubscriptionsB INNER JOIN
        Calendar.Quarters AS QuartersB ON SubscriptionsB.TerminationMonth = QuartersB.CompanyFiscalQuarter
ORDER BY TrackerA.Zone, SubscriptionsA.ActivationDate

Tables are as follows:

-Zone: ZoneID (PK)
-TrackerAccounts: Tracked Account (PK), Zone (FK)
-SweepAccounts: SweepAccount (PK, FK on TrackerAccounts), MasterAccountListId (FK on MasterAccountList)
-MasterAccountList: MasterAccountListId (PK)
-Subscriptions: SubscriptionId (PK), SnlId (FK on MasterAccountList), ProductCode (FK on ProductParent)
-ProductParent: ProductCode (PK)

-Quarters: MonthNumber (PK)

  • 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-05-22T21:31:33+00:00Added an answer on May 22, 2026 at 9:31 pm

    Your problem is that when you say , Products.Subscriptions AS SubscriptionsB you’re doing a cross join, so it’s going to output NxN rows where N is the total number of subscriptions. I doubt you need that join at all, since you don’t appear to be using any values from that instance i.e this should work just fine:

    SELECT ZoneA.ZoneDescription
            ,TrackerA.Zone
            ,MasterListA.Name
            ,SubscriptionsA.ActivationDate
            ,SubscriptionsA.TerminationDate
            ,ParentA.ProductParentType
            ,MONTH(SubscriptionsA.ActivationDate) AS ActivationMonth
            ,MONTH(SubscriptionsA.TerminationDate) AS TerminationMonth
            ,QuartersA.CompanyFiscalQuarter AS ActivationQuarter
            ,QuartersB.CompanyFiscalQuarter AS TerminationQuarter
    FROM BalanceTracker.Zone AS ZoneA INNER JOIN
            BalanceTracker.TrackerAccounts AS TrackerA ON ZoneA.ZoneID = TrackerA.Zone INNER JOIN
            BalanceTracker.SweepAccounts AS SweepA ON TrackerA.TrackedAccount = SweepA.SweepAccount INNER JOIN
            Fed.MasterAccountList AS MasterListA ON SweepA.MasterAccountListID = MasterListA.MasterAccountListID INNER JOIN
            Products.Subscriptions AS SubscriptionsA ON MasterListA.MasterAccountListID = SubscriptionsA.SnlId INNER JOIN
            Products.ProductParent AS ParentA ON SubscriptionsA.ProductCode = ParentA.ProductCode INNER JOIN
            Calendar.Quarters AS QuartersA ON SubscriptionsA.ActivationMonth = QuartersA.MonthNumber LEFT JOIN
            Calendar.Quarters AS QuartersB ON SubscriptionsA.TerminationMonth = QuartersB.CompanyFiscalQuarter
    ORDER BY TrackerA.Zone, SubscriptionsA.ActivationDate
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get my head round this (okay, tbh cramming a night before
Okay, so I'm trying to get into this whole HTML 5 thing, and this
I'm trying to get a list of users from the Active Directory, who have
okay, I'm still trying to get my head around some of the caching stuff
Okay...so, I've got everything written correctly...however, when trying to get the grand total of
Okay I have been trying to get this to work for some time now.
I am trying to get data from LivEx table as list, and then save
Okay, I've been trying to get this for almost 4 hours now, and it
okay, so I'm trying to get a directory of folders and sub folders, but
Okay I'm trying to go for a more pythonic method of doing things. How

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.