SQL - Trying to collapse detail into one summary row. Either with dynamic sql or Microsoft Access

I am trying to write a sql statment that will collapse the  following data into 1 row. Data is in excel file listed below
AGREEMENT_ID	PR_AUTHORIZAION	PR_DNIS	PR_ANI_NUM	PR_SLCT_9_DAT_REF_NUM	PR_KEYLINE_PROMO_NUM	SOLICITATION_OPERATOR_ID
76887596	312944366	null	null	null	null	null
76887596	null	null	null	153380647	null	null
76887596	null	null	2256872695	null	null	null
76887596	null	null	null	null	null	bta76478
76887596	null	null	null	null	Q33	null
76887596	null	08763	null	null	null	null
						
Final Output						
AGREEMENT_ID	PR_AUTHORIZAION	PR_DNIS	PR_ANI_NUM	PR_SLCT_9_DAT_REF_NUM	PR_KEYLINE_PROMO_NUM	SOLICITATION_OPERATOR_ID
76887596	312944366	08763	2256872695	153380647	Q33	bta76478

Open in new window

AgrmeentTest.xlsx
centralmikeAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
E.g.

DECLARE @Sample TABLE ( AGREEMENT_ID INT, PR_AUTHORIZAION INT, PR_DNIS VARCHAR(255) );

INSERT INTO @Sample
VALUES	( 76887596, 312944366, NULL ),
	( 76887596, NULL, '08763' );

SELECT	S.AGREEMENT_ID,
	MAX(S.PR_AUTHORIZAION),
	MAX(S.PR_DNIS)
FROM	@Sample S
GROUP BY S.AGREEMENT_ID

Open in new window

PortletPaulEE Topic AdvisorCommented:
Please note I added a plain text version of your spreadsheet to the question as it makes it easier to read (especially on small devices).

What ste5an has correctly suggested is to use a GROUP BY clause, and the MAX() function on each of those columns that have just one non-null value.
SELECT
      AGREEMENT_ID
    , MAX(PR_AUTHORIZAION) AS PR_AUTHORIZAION
    , MAX(PR_DNIS) AS PR_DNIS
    , MAX(PR_ANI_NUM) AS PR_ANI_NUM
    , MAX(PR_SLCT_9_DAT_REF_NUM) AS PR_SLCT_9_DAT_REF_NUM
    , MAX(PR_KEYLINE_PROMO_NUM) AS PR_KEYLINE_PROMO_NUM
    , MAX(SOLICITATION_OPERATOR_ID) AS SOLICITATION_OPERATOR_ID
FROM TBL_Defects_DCRs
GROUP BY
      AGREEMENT_ID

Open in new window

I would like to see your current query if possible.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.