Solved

SQLP pivot columns into new row column from duplicate key

Posted on 2014-07-30
3
331 Views
Last Modified: 2014-08-11
I have created a table which contains a rownumber, memberid and Datestart,, dateEnd.  The problem is that I can have duplicate memberid's.  I need to interogate the date ranges on all the duplicate rows to do GAP analysis on the date ranges .  I have been searching for a PIVOT example to pivit the date columns into one row.

See the attached file for the problem visual. where the row is greater than 1 I need to add the dates to  the first.
Capture2.PNG
0
Comment
Question by:rschmehl
3 Comments
 
LVL 48

Expert Comment

by:PortletPaul
ID: 40231354
I have almost no idea what you are asking for. Sorry if that seems rude, I'm just being honest.

>>"The problem is that I can have duplicate memberid's. "
are you trying to solve this?

>>"I need to interrogate the date ranges ... to pivot the date columns into one row."
is this the request?    ( If so, what does this actually mean? please provide an example)

The graphic does not reveal your problem to me (i.e. it isn't self evident ,,, to me)
--------------------

The best, most effective, and fastest way to get your message across is through the following:

A: Some sample data (ideally this is a table definition and some inserts; or it might simply be a copy/paste of some data into a code block. But is not an image of data, it is actual reusable data we can get into a table)

B: an "expected result"
This might be a graphic but more likely it would be an area of an Excel sheet that displays the output you are looking for. This should be based on the sample data.

With these we have the tools to understand the problem and to test if we can solve the problem. And you don't have to use so many words to describe the problem either.

---------
please provide some sample data and an expected result.
0
 
LVL 1

Accepted Solution

by:
Irek Piwowarek earned 500 total points
ID: 40245791
As I understand your issue, you want to extend dates from row 1 by dates from row 2. I see some solutions here;
1. Left join by memeberid, memeberCIM (left side row 1 and right side row 2) this way you will remove duplicates and can extend dates
2. Group by memeberid, memeberCIM and find min from startdate and max from enddate (removes duplicates and extends dates)

I hope this helps.
0
 

Author Closing Comment

by:rschmehl
ID: 40253440
Thank you.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This video discusses moving either the default database or any database to a new volume.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now