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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:24:37+00:00 2026-06-16T21:24:37+00:00

I’m having two tables 1) T_SETTLEMENT_Transaction (master table) 2) T_SETTLEMENT_Activity (child table) Data in

  • 0

I’m having two tables

        1) T_SETTLEMENT_Transaction (master table)
        2) T_SETTLEMENT_Activity (child table)

Data in T_SETTLEMENT_Transaction table;

SettlemtTransactionID(pk) PC_TransactioID  Form_Of_PAyment  AgentName    CreatedeDateTime         PaymentTransaDate
1000                       1753014          CASH              Test1       2013-01-10 21:00:00.937  2013-01-10 21:00:00.937
1001                       1456325          Check             test2       2013-01-10 21:00:00.937  2013-01-10 21:00:00.937

Data in T_SETTLEMENT_Activity Table;

SettlementActivity_ID(pk)   SettlementTransactionID(foreighKey) RoutingNumber  SettlementAmount   SettlemtDate             SettlementStatus SettlementType Bank_Account_NUM
 1                             1000                                1111111111     525            2013-01-10 21:00:00.937       PEND             STL       1234567890
 2                             1001                                1111111122     625             2013-01-10 21:00:00.937       PEND             STL       1234567891
 3                             1000                                1111111111     25             2013-01-13 21:10:00.937       PEND             FEE       1234567890

Requirement scenario is:

1)

 Im selecting records based on "date" , "PEND" & "STL" status from 
 "settlementDate", "settlement_status" and "settlemnt_trans_type" columns.

2)

  If "STL" status record is having "FEE" record then i should add
  SettlementAmount of "FEE" record to "STL" record and only "STL" record should be retrieved.
  (we are checking "STL" is having "FEE" record or Not based on Settlement_TransactionId column (Pls refer the tables i mentioned above)). 

3)

 I would insert the "FEE" record for same Settlement_TransactionID 
 (eg.for Settlement_TransactionID=1000 )on same day of inserting "STL" record(if im having FEE record for that) or after 3 days(approx 3 or 5 days)  with different SETTLEMENT_DATE(which is in  
 selected column ).     

Kindly see the (expected output)table data shown below which tells the expected output i want

I join two table like below

 SELECT DISTINCT sum(xa.SETTLEMENT_AMOUNT) AMT,
                xa.ROUTING_NUMBER,
                xa.BANK_ACCOUNT_NUM,
                xa.SETTLEMENT_DATE   
                xa.SETTLEMENT_TRANSACTION_ID
                xt.PAYMENT_AGENT_NAME
                xt.PC_TRANSACTION_ID
                xt.CREATED_DATE_TIME,
                xt.PAYMENT_TRANS_DATE
                        FROM
    PCTransDB.dbo.T_SETTLEMENT_Transaction xt,
    PCTransDB.dbo.T_SETTLEMENT_Activity xa
    with (NOLOCK)
    where xa.SETTLEMENT_DATE <='2013-01-10 21:00:00.937'
     and xa.SETTLEMENT_STATUS='PEND'
     and xa.SETTLEMENT_TRANS_TYPE in('FEE','STL')
     and xt.SETTLEMENT_TRANSACTION_ID=xa.SETTLEMENT_TRANSACTION_ID 
            group by xa.SETTLEMENT_TRANSACTION_ID,
                     xa.ROUTING_NUMBER,
                     xa.BANK_ACCOUNT_NUM,
                     xa.SETTLEMENT_DATE  
                     xa.SETTLEMENT_TRANSACTION_ID 
                     xt.PAYMENT_AGENT_NAME
                     xt.PC_TRANSACTION_ID
                     xt.CREATED_DATE_TIME,
                     xt.PAYMENT_TRANS_DATE;

The current output for the above query is

 AMT    Routing Number    Bank_Account_Num  SETTLEMENT_DATE       SETTLEMENT_TRANSACTION_ID PAYMENT_AGENT_NAME  PC_TRANSACTION_ID  CREATED_DATE_TIME        PAYMENT_TRANS_DATE
525.00    111111111     1234567890          2013-01-01 20:00:00.0   1000                    TEST                171477             2012-06-25 00:00:00.0       2012-06-25 00:00:00.0
25.00      111111111    1234567890          2013-01-02 20:10:00.0   1000                    TEST                 171477            2012-06-  25 00:00:00.0  2012-06-25 00:00:00.0
625.00   111111122       1234567891         2013-01-01 20:00:00.0   1001                    TEST1               171478             2012-06-25 00:00:00.0    2012-12-25 21:00:00.0       

But my expected output is like below

 AMT    Routing Number    Bank_Account_Num  SETTLEMENT_DATE       SETTLEMENT_TRANSACTION_ID PAYMENT_AGENT_NAME  PC_TRANSACTION_ID  CREATED_DATE_TIME        PAYMENT_TRANS_DATE
550.00    111111111     1234567890          2013-01-02 20:10:00.0   1000                    TEST                171477             2012-06-25 00:00:00.0       2012-06-25 00:00:00.0

625.00   111111122       1234567891         2013-01-01 20:00:00.0   1001                    TEST1               171478             2012-06-25 00:00:00.0    2012-12-25 21:00:00.0

Pls correct me if im making wrong in the query to get the expected output.

Note: Im Pasting my table columns here:

T_SETTLEMENT_TRANSACTION

    SETTLEMENT_TRANSACTION_ID     NUMERIC(12,0)
    PC_TRANSACTION_ID             NUMERIC(12,0)
    PAYMENT_SOURCE_SYSTEM         VARCHAR(9)
    TRANSACTION_AMOUNT            NUMERIC(9,2)
    PAYMENT_AGENT_ID              VARCHAR(10)
    PAYMENT_AGENCY_ID             VARCHAR(10)
    USER_CLUB_CODE                VARCHAR(3)
    FORM_OF_PAYMENT               VARCHAR(4)
    PAYMENT_TRANS_DATE            DATETIME
    PAYMENT_USERREPO_AGENT_ID   VARCHAR(20)
    PAYMENT_AGENT_STATE           VARCHAR(10)
    PAYMENT_AGENT_NAME            VARCHAR(100)
    ACH_REJECT_COUNTER            BIGINT
    CREATED_BATCH_ID              VARCHAR(50)
    CREATED_DATE_TIME             DATETIME

2)
T_SETTLEMENT_ACTIVITY

     SETTLEMENT_ACTIVITY_ID          NUMERIC(12,0)
     SETTLEMENT_TRANSACTION_ID       NUMERIC(12,0)
     ORDER_TRACE_NUMBER              VARCHAR(15)
     SETTLEMENT_STATUS               VARCHAR(10)
     SETTLEMENT_TRANS_TYPE           VARCHAR(10)
     SETTLEMENT_AMOUNT               NUMERIC(9,2)
     ROUTING_NUMBER                  VARCHAR(9)
     BANK_ACCOUNT_NUM                VARCHAR(20)
     SETTLEMENT_DATE                 DATETIME
     ACH_SUBMISSION_DATE_TIMESTAMP     DATETIME
     ACH_REJECT_CODE                 VARCHAR(10)
     ACH_TRACE_NUMBER                VARCHAR(15)
     ACH_RETURN_TRACE_NUMBER         VARCHAR(15)
     CREATED_BATCH_ID                VARCHAR(50)
     CREATED_DATE_TIME               DATETIME
     TRANS_XREF                      NUMERIC(12,0)
     NSF_XREF                        NUMERIC(12,0)
     MODIFIED_BY                     VARCHAR(50)
     LAST_MODIFIED_DATE_TIME         DATETIME
     SETTLEMENT_CANCEL_REASONCODE     VARCHAR(10)
  • 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-16T21:24:39+00:00Added an answer on June 16, 2026 at 9:24 pm

    This query seems to produce the desired output. But the query you posted can’t possibly run, and the sample data can’t possibly work. The column “BANK_ACCOUNT_NUM” isn’t associated with any sample data, and it’s in the GROUP BY clause, so it could be throwing you off.

    SELECT DISTINCT sum(xa.SETTLEMENT_AMOUNT) AMT,
                    xa.ROUTING_NUMBER,
                    xa.BANK_ACCOUNT_NUM,
                    xa.SETTLEMENT_DATE,
                    xa.SETTLEMENT_TRANSACTION_ID,
                    xt.PAYMENT_AGENT_NAME,
                    xt.PC_TRANSACTION_ID,
                    xt.CREATED_DATE_TIME,
                    xt.PAYMENT_TRANS_DATE
    FROM
        T_SETTLEMENT_Transaction xt,
        T_SETTLEMENT_Activity xa
    where xa.SETTLEMENT_DATE <='2013-01-10 21:00:00.937'
      and xa.SETTLEMENT_STATUS='PEND'
      and xa.SETTLEMENT_TRANS_TYPE in('FEE','STL')
      and xt.SETTLEMENT_TRANSACTION_ID=xa.SETTLEMENT_TRANSACTION_ID 
    group by xa.SETTLEMENT_TRANSACTION_ID,
             xa.ROUTING_NUMBER,
             xa.BANK_ACCOUNT_NUM,
             xa.SETTLEMENT_DATE,
             xa.SETTLEMENT_TRANSACTION_ID, 
             xt.PAYMENT_AGENT_NAME,
             xt.PC_TRANSACTION_ID,
             xt.CREATED_DATE_TIME,
             xt.PAYMENT_TRANS_DATE;
    

    In working out SQL problems, it’s often helpful to simplify to something like this.

    SELECT DISTINCT 
        sum(xa.SETTLEMENT_AMOUNT) AMT,
        xa.SETTLEMENT_TRANSACTION_ID
    FROM
        T_SETTLEMENT_Transaction xt,
        T_SETTLEMENT_Activity xa
    where xt.SETTLEMENT_TRANSACTION_ID=xa.SETTLEMENT_TRANSACTION_ID 
    group by xa.SETTLEMENT_TRANSACTION_ID;
    

    When that works, you can add more columns and WHERE conditions.

    In the future post working DDL and SQL INSERT statements. That will let people here just paste code and run it. Much faster than trying to figure out all your column misnamings, data truncations, and misleading data.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I've tracked down a weird MySQL problem to the two different ways I was
I'm trying to select an H1 element which is the second-child in its group
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I want to construct a data frame in an Rcpp function, but when I
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.