Firstly, apologies if anyone has already read this in a previous entry but I am still wondering how best to tackle this. Here we go....
Basically, I have a query similar to the one below that will be used as a basis for generating a CSV file but i need 3 rows (containing the literal values) preceding the results.
Query:
DECLARE @MyTable TABLE (EmployeeID VARCHAR(10), Hours REAL, HoursType VARCHAR)
INSERT INTO @MyTable
SELECT
'001', 3.5, 'A'
UNION ALL
SELECT
'001', 8, 'B'
UNION ALL
SELECT
'002', 10, 'A'
SELECT *
FROM
@MyTable PIVOT (SUM(Hours) FOR HoursType IN (A,B) ) AS p
Literal values:
< DEFN > |
< EMPID > | < COSTCEN >
< DATA > |
So, in summary i need the result set to look something like this....
< DEFN > |
< EMPID > | < COSTCEN >
< DATA > |
001 | 3.5 | 8
002 |10 | NULL