x

Transpose a single row to multiple column in SQL Server

I have my sql data with column headers as below : alt text

And I want my output as

alt text

That means I need all the columns in source as like same. But WeekDate Column should go as separate columns using SQL Server.

How can I achieve this. Please help.

sqlsource.jpg (25.0 kB)
sqltarget.jpg (115.7 kB)
more ▼

asked Sep 11 at 07:25 AM in Default

avatar image

Maha1991
1 1

Easier to see with some actual data supplied; but I think you're looking for something like either a PIVOT or a Cross Tab. See @Jeff Moden's article - http://www.sqlservercentral.com/articles/T-SQL/63681/

Sep 11 at 12:35 PM ThomasRushton ♦♦

Are the Forecast/Actual columns in the Target supposed to come from the AssignedEffort/LatestEffort columns in the source?

Sep 11 at 02:00 PM Jeff Moden

Yes You are right, Jeff

Sep 12 at 04:39 AM Maha1991
(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

Hi, To be more clear I have modified the source and required Target as below : Please look into it. Thank you for your help in advance.

alt text

sqlsource.jpg (254.2 kB)
sqltarget.jpg (131.2 kB)
more ▼

answered Sep 12 at 04:36 AM

avatar image

Maha1991
1 1

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x148
x121
x1

asked: Sep 11 at 07:25 AM

Seen: 29 times

Last Updated: Sep 12 at 04:39 AM

Copyright 2017 Redgate Software. Privacy Policy