I'm trying to join two tables together, that only share an "Account Number" as a joining field between them. One table (Table1) is static and contains just one record per account number, but the other joining table (Table2) contains multiple Date records per account number. Using a Temp Table, I'm trying to first pull distinct Date records from Table2 and then join them to Table1 via the Account Number.
SELECT DISTINCT CAST(tlpsf.ACCOUNT_NUMBER AS NCHAR(16)) AS psAccountNumber ,tlpsf.APPL_ID AS psApplID --,MIN(CONVERT(VARCHAR(10),tlpsf.DATE_PYMT_DUE_FIRST,120)) AS psDatePmtDueFirst ,MIN(CAST(tlpsf.DATE_PYMT_DUE_FIRST AS datetime2)) AS psDatePmtDueFirst ,tlpsf.NBR_OF_PMTS_THIS_SCHEDULE AS psNbrPmtsThisSchedule , CAST(tlpsf.PAYMENT_SCHEDULE_AMOUNT AS NUMERIC(17,2)) AS psPmtScheduleAmt , tlpsf.PAYMENT_SCHEDULE_TYPE AS psPmtScheduleType , tlpsf.ROW_PROCESSED_THRU AS psRowProcessedThru INTO #loanpmtschedules FROM dbo.T_LOAN_PYMT_SCHEDULE_FILE_ME tlpsf WHERE tlpsf.ROW_PROCESSED_THRU = @strLastofMonth GROUP BY ACCOUNT_NUMBER, APPL_ID, NBR_OF_PMTS_THIS_SCHEDULE, PAYMENT_SCHEDULE_AMOUNT, PAYMENT_SCHEDULE_TYPE, ROW_PROCESSED_THRU
However, for some reason my Temp table build is still pulling in multiple date records, per account number.