Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
yoshidahiro
Starting Member
2 Posts |
Posted - 2015-04-17 : 13:07:11
|
I am querying a table with multiple rowsSELECT caseId, Name ,CompletedDate FROM TableZthe number of results per CaseID are varable some have 1 record others up to 36 recordsI need to pivot the results based off of the competed date Name has 20 distinct values but we can have diplicatesso something likeCase Name Date1 This 2015-01-011 That 2015-01-032 That 2013-01-012 Then 2014-12-032 This 2015-01-012 There 2015-04-033 This 1999-01-013 That 2001-01-023 This 2006-01-01looks like this1 This That2 That Then This There3 This That This |
|
yoshidahiro
Starting Member
2 Posts |
Posted - 2015-04-17 : 13:08:24
|
BTW I dont really care what the column names are but I would like to be able to doStep1 step2 as column names if possible |
|
|
kostya1122
Starting Member
15 Posts |
Posted - 2015-04-20 : 21:09:01
|
something like thisselect * , row_number() over ( partition by case order by date desc) as rowinto #tablefrom tableselect case,max([1]) as step1,max([2]) as step2,max([3]) as step3from tablepivot(max(name)for row in ([1],[2],[3])) as pvtgroup by case |
|
|
|
|
|