question

b.joseph avatar image
b.joseph asked

Hi, How can i transpose rows to columns without calculation in SQL Server

Hi I have to transpose rows to columns

I have simple table like below

ID REQUESTID ACTION_MEMBER_ID
1  	1       	10             
2 	1       	15
3	2		11
4	2		12

I want to convert to

REQUESTID 	AMID1 	AMID1
1		10	15
2		11	12

Kindly let me know how can i do this, i tried code snippets but all with max,sum,count functions.Action members can be dynamic,so the columns should arrange according to that

pivot
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

· Write an Answer
Jon Crawford avatar image
Jon Crawford answered

You want to look up a dynamic pivot statement, there are articles that will explain it better than I can.

1 comment
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

or a dynamic cross tab statement - There are articles on the main SQL Server Central website that cover these, such as https://www.sqlservercentral.com/articles/cross-tabs-and-pivots-part-2-dynamic-cross-tabs

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.