0

I have the below query

SELECT TOP 10
    pkRowId AS [Row Guid],
    fkItemId AS [Item Guid],
    SortOrder AS [SortOrder],
    IsMain,
    Updated,
    REPLACE(Url, 'i.ebayimg.com', 'ecx-images.amazon.com') AS [Url],
    ROW_NUMBER() OVER (PARTITION BY fkItemId ORDER BY SortOrder) AS [Row Number]
FROM 
    [download].[item_image] 

which displays data in the below format:

Input

which I would like to be displayed in the following format:

Result

How can I pivot my source so that Url1 displays the Url where IsMain is true?

  • 7
    This has been asked and answered hundreds and hundreds of times. Do none of the duplicates for this work for you? Also using string literals as column alias has been deprecated for quite some time. And you really shouldn't add spaces. It makes things more difficult. https://sqlblog.org/2012/01/23/bad-habits-to-kick-using-as-instead-of-for-column-aliases – Sean Lange Oct 09 '18 at 21:11
  • 1
    You can start from [here](https://stackoverflow.com/questions/10404348/sql-server-dynamic-pivot-query) – Andrea Oct 10 '18 at 09:08
  • @SeanLange Spaces were added for readibility. Also, it's not necessary that everyone has the permissions to run `%:Deprecated Features`. – Navik Goswami Oct 10 '18 at 09:17
  • 1
    Not sure I understand what you mean about deprecated features. Using strings as aliases has been deprecated for a long time. Pretty sure since sql 2005. As for the task at hand, did you find an example of this? – Sean Lange Oct 10 '18 at 13:20

0 Answers0