I am using C# with SQL Server 2005.
I have a table that looks like this:
EmpID Code
----------- --------
101 A1
101 B1
101 C1
102 A1
102 C1
103 B1
103 D1
I want to write like this in a text file:
EmpID A1 B1 C1 D1
-----------------------------------------------
101 10 20 10 0
102 100 0 150 0
103 0 100 0 120
----------------------------------------------
Firstly, how to convert column values into row. Secondly, while
writing into text file, I want the column headings and later the
records below in a fixed size so that they align with the headings.
Ignacio Machin ( .NET/ C# MVP ) - 28 Aug 2007 15:57 GMT
Hi,
Sql 2005 provides a way to convert rows into columns , take a look at Pivot
Formatting it is easy, you can do it from SQL itself, just use char columns
>I am using C# with SQL Server 2005.
>
[quoted text clipped - 24 lines]
> writing into text file, I want the column headings and later the
> records below in a fixed size so that they align with the headings.