0

Here is a simple query and it's results using SQL Server:

SELECT Notes
FROM DailyTaskHours
WHERE Notes IS NOT NULL
    AND Notes <> ''
    AND NonScrumStoryId = 2264

enter image description here

I would like one row with one column returned. How do I accomplish this?

David Tunnell
  • 7,252
  • 20
  • 66
  • 124

2 Answers2

1

If this is a SQL Server Database I believe you can implement the PIVOT operator in a way like this:

select [1] as field1,
  [2] as field2,
  [3] as field3
from
(
  select col1, row_number() Over(order by col1) rn
  from yourtable
) src
pivot
(
  max(col1)
  for rn in ([1], [2], [3])
) piv
Jason Roell
  • 6,679
  • 4
  • 21
  • 28
1

I'm figuring you need them all as a single cell, rather than PIVOT them out.

Try this

With 
MyTable as
(
        Select 1 Id, 'Contacted the P6 Admin Reps to find out what to do.' Notes
Union   Select 2, 'Sent and email to request status.'
Union   Select 3, 'updated ticket and confirmed issue was resolved.'
) 
Select 
    (
        SELECT SUB.Notes + ' ' 
        FROM MyTable SUB
        FOR XML PATH('')
    ) TextValue 

Here is the answer I get:

TextValue
---------------------------------------------------------------------------------------------------------------------------------------
Contacted the P6 Admin Reps to find out what to do. Sent and email to request status. updated ticket and confirmed issue was resolved. 

(1 row(s) affected)
Raj More
  • 47,048
  • 33
  • 131
  • 198