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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:19:45+00:00 2026-05-20T18:19:45+00:00

I need to implement functionality of nightly process in my applications billing module. See

  • 0

I need to implement functionality of nightly process in my applications billing module. See the image of the tables involved.
enter image description here

Let me explain tables by their numbers in red. Basically this is an house allotment application database where the tenants can choose the billing plans and addons in it. Like we have inour mobile service.

Step: 1. This is the first most table, tbl_MSTBilling, where the enduser will create a plan with some addon. Addon is known as transaction type here. There billing plan general details are saved here in the same details where as the addons will get saved into table no 2 with reference of the billing plan, that is the billing plan id. Also here in table 1 we have two entities BillingDayOfMonth as integer and LatefeeAppliedDayOfMonth as int. Which takes input in between 1-31 (days of months).

Step 2: Now at the time of agreeement, tenant opts some billing plan that suits him and that billing plan is then attached with the agreement. In table 3 , we have agreement id and billingplanid. Now we agreement is generated the addons of billing plan from table 2 will get inserted into table 4. Here Agreement and BillingPlan has 1:1 relationship.

Sterp3: Now the scenario of nightly process come, which will occur every night. First it will check the Billing day of month in table 3, It will have to pull out the agreements id of all user having their billing day of month as today. Now on the basis of all agreements the rows from table 4 will get populated into table 5. Here TransactionDate will be null for each row and Statementdate will become current date. TransactionType of 4 is as same as TransactionTypeId of 5. Say we got 100 rows of 20 different AgreementId’s.Also in the mean while we have to check in table 6 whether there is any bill due for agreement on the basis of includedinstatement, which is bit field. If this is included then it will get set to true.

Step 4: Taking table 5 and 7 a single row will get inserted to table 7 which will be the original bill.

So this is my entire query. I got stucked at step 3, where nightly process starts. I hope i am clear to you. Any queries please put it.

My Current Sql Script

    BEGIN TRY

        BEGIN TRANSACTION
            DECLARE @Today AS INT
            --
            SET @Today =12-- (SELECT DATEPART(DAY,GETDATE()))

            -- First of all check for the agreements 
            INSERT INTO tbl_AccountTranscation (AgreementID,TranscationDate,TranscationTypeID,Amount,StatementDate)
            SELECT AgreementId, NULL, TransactionType,Amount,GETDATE() FROM tbl_AgreementTransaction
            WHERE AgreementId IN (SELECT AgreementId From tbl_MSTAgreement WHERE BillingDayOfMonth = @Today)


            Declare @Count AS INT
            SET @Count = (Select COUNT(*) FROM tbl_BillDue WHERE IncludedinStatement=0 AND AgreementID IN (SELECT AgreementId 
                                                                                                           From tbl_MSTAgreement 
                                                                                                           WHERE BillingDayOfMonth = @Today) )
            IF @Count >0 
                BEGIN
                    INSERT INTO tbl_AccountTranscation (AgreementID,TranscationDate,TranscationTypeID,Amount,StatementDate)
                    Select  AgreementId,NULL,-1,ISNULL(((ISNULL(TotalDueAmount,0)+ ISNULL(LateFeeAmount,0)) - ISNULL(AdjustmentAmount,0)),0) as Amount, 
                            GETDATE() as StatementDate
                    From tbl_BillDue
                    Where IncludedinStatement = 0 and AgreementID IN (  SELECT AgreementId 
                                                                        From tbl_MSTAgreement 
                                                                        WHERE BillingDayOfMonth = @Today
                                                                    )
                END                 
            --INSERT INTO tbl_MSTBill
            --(AgreementId,OutStandingPayment,BillDate,BillDueDate,PaymentDate,AmountPaid)
            --SELECT AgreementID, SUM(Amount) as Amount,StatementDate,NULL,NULL,NULL  
            --FROM  tbl_AccountTranscation WHERE AgreementId IN ( SELECT AgreementId 
            --                                                  From tbl_MSTAgreement 
            --                                                  WHERE BillingDayOfMonth = 12)

            --GROUP BY AgreementID, Amount,StatementDate

            SELECT     tbl_MSTAgreement.AgreementID, tbl_MSTAgreement.LateFeeApplyDayOfMonth, tbl_AccountTranscation.StatementDate, 
                     SUM(tbl_AccountTranscation.Amount) as Amount
FROM         tbl_AccountTranscation INNER JOIN
                      tbl_MSTAgreement ON tbl_AccountTranscation.AgreementID = tbl_MSTAgreement.AgreementID
                      GROUP BY tbl_MSTAgreement.AgreementID,Amount,tbl_MSTAgreement.LateFeeApplyDayOfMonth, tbl_AccountTranscation.StatementDate
        COMMIT TRANSACTION
    END TRY
    BEGIN CATCH
        ROLLBACK TRANSACTION

    END CATCH
END
  • 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-20T18:19:45+00:00Added an answer on May 20, 2026 at 6:19 pm

    If it’s the scheduling which is the hard part for you, you can either use either a scheduled job with the SQL Agent to do your nightly work in a stored procedure, or you can write a console application which does the same which you execute via Windows built-in scheduled tasks.

    The code itself shouldn’t be that hard from browsing your requirements.

    Good luck 🙂

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

Sidebar

Related Questions

I need to implement a functionality to allow users to enter price in any
I am working on one project where there is a functionality need to implement
i need to implement the email signature with image.As of now we only support
I'm new to WPF but I need to implement following functionality: I have a
I need to implement some workflow functionality; for example, user submits a document, it
I need to implement a drag and drop functionality, where I can define and
Need to implement functionality similar to what dotdotdot jQuery plugin does but cannot use
I need to implement undo-redo functionality in my project. But it is very complex
I need to implement an Autocomplete functionality which display names and faces like in
I have two instances in an application where I need to implement functionality to

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.