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
Solved

SQLP pivot columns into new row column from duplicate key

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Addition to SQL for dynamic fields 6 47
How to debug a store procedure in MS SQL 2008? 3 23
Present Absent from working date rage 11 37
Stored Proc - Rewrite 42 59
A recent question popped up and the discussion heated up regarding updating a COMMENTS (TXT) field in a table using SSRS. http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/MS-SQL_Reporting/Q_27475269.html?cid=1572#a37227028 (htt…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
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…

856 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