Solved

SQLP pivot columns into new row column from duplicate key

Posted on 2014-07-30
3
348 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 49

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

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

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

It is helpful to note: This is a cosmetic update and is not required, but should help your reports look better for your boss.  This issue has manifested itself in SSRS version 3.0 is where I have seen this behavior in.  And this behavior is only see…
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.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

705 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