Solved

SQLP pivot columns into new row column from duplicate key

Posted on 2014-07-30
3
347 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

749 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