Solved

SQLP pivot columns into new row column from duplicate key

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction In the following article I’ll be discussing and demonstrating several different ways of how images can be put on a report. I’m using SQL Server Reporting Services 2008 R2 CTP, more precisely version 10.50.1352.12, but the methods ex…
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.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 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

27 Experts available now in Live!

Get 1:1 Help Now