SQL: pivot non numeric data I have a set of data which basically looks like the following:
+---------+--------+
| EventId | Field  |
+---------+--------+
|       1 | apple  |
|       1 | paper  |
|       1 | boy    |
|       2 | banana |
|       2 | cat    |
|       3 | girl   |
+---------+--------+

I would like to pivot this to look like this:
+-------+--------+------+
|   1   |   2    |  3   |
+-------+--------+------+
| apple | banana | girl |
| paper | cat    |      |
| boy   |        |      |
+-------+--------+------+

I am trying to fiddle around PIVOT, but I can't get the result I want.
Am I looking at or using the wrong command? Is PIVOT the correct relational operator for this?
This is the code I have been working on so far:
DECLARE @columns NVARCHAR(MAX), @sql NVARCHAR(MAX);
SET @columns = N'';
SELECT @columns += N', ' + QUOTENAME(EventID)
  FROM (
            select distinct
                EventId
            from Events
        ) AS x;

SET @sql = 
N'select  ' + 
STUFF(@columns, 1, 2, '') +  ' 

into ##tempMap from
(
    select
        ev.EventID,ev.FieldName
    from Events ev
) as a
pivot 
(
      max(FieldName) for EventId in ('
  + STUFF(REPLACE(@columns, ', p.[', ',['), 1, 1, '')
  + ')
) as pivottable;';

EXEC sp_executesql @sql

select * from ##tempMap
drop table ##tempMap

The code above returns the following results because of the MAX aggregate function.
+-------+-----+------+
|   1   |  2  |  3   |
+-------+-----+------+
| paper | cat | girl |
+-------+-----+------+
This answer isn't dynamic, but shows you how to achieve the goal in pure TSQL, making it dynamic should be straightforward.
Essentially, you just need to add another column to spread the data out so that the MAX(fieldname) isn't the max for the event.  I've chosen to use a ROW_NUMBER partitioned by the EventID so that each entry for each event is also numbered.
I did also look at https://stackoverflow.com/questions/1343145/tsql-pivot-without-aggregate-function
DROP TABLE IF EXISTS ##Events 

CREATE TABLE ##Events 
    (
    EventID INT NOT NULL
    , FieldName VARCHAR(20) NOT NULL
    )

INSERT INTO ##Events 
    (EventID, FieldName)
VALUES (1, 'apple')
    , (1, 'paper')
    , (1, 'boy')
    , (2, 'banana')
    , (2, 'cat')
    , (3, 'girl')

;WITH CTE_RN AS 
    (
    SELECT EventID
        , FieldName 
        , RN = ROW_NUMBER() OVER (PARTITION BY EventID ORDER BY FieldName)
    FROM ##Events AS E
    )
SELECT [1]
    , [2]
    , [3]
FROM CTE_RN
    PIVOT (MAX(FieldName) FOR EventID IN ([1], [2], [3])) AS pvt