How to have row data as columns SQL Query

Hi,
I have a table with sample data:

GroupID, TaskID, LaborID, QTY
1, Fix Bulbs, 3, 5
1, Fix Stairs, 3, 2
1, Fix XYZ, 4, 1

I want to write a query that would display the LaborID as columns, and the TaskID as the rows.
I suppose this is Pivot, but I am not clear. Been a long month.
melegant99Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
tigin44Connect With a Mentor Commented:
then you should create the pivot sql dynamically...

just create this part [1],[2],[3],[4],[5],[6] from the table by using a query that will include all the values.. and concat it twith the given query and execute it...

0
 
tigin44Commented:
simple try this
SELECT TaskID, [1],[2],[3],[4],[5],[6]
FROM (

		SELECT TaskID, LaborID 
		FROM yourTable	
	) P
	PIVOT
	(
		MAX(LaborID) FOR LaborID IN ([1],[2],[3],[4],[5],[6])
	) AS pvt
ORDER BY TaskID

Open in new window

0
 
melegant99Author Commented:
I don't know what the LaborID's will be though in advance, it could be any varying amount and ID #.
0
All Courses

From novice to tech pro — start learning today.