Friday, March 30, 2012

reader headers of table

I have a table that has :
date, leader_count, employee_count, manager_count
10/14/2005, 4 ,5 ,5
Any idea how I can almost transpose the table to create a table that looks
like:
date, type, count
10/14/2005, leader, 4
10/15/2005, employee, 5
Thanks for any suggestions.what do you mean transpose, how about using a view ?
"AshleyT" <AshleyT@.discussions.microsoft.com> wrote in message
news:07EF85C2-5F94-4E60-86B6-A9713160D21C@.microsoft.com...
>I have a table that has :
> date, leader_count, employee_count, manager_count
> 10/14/2005, 4 ,5 ,5
> Any idea how I can almost transpose the table to create a table that looks
> like:
> date, type, count
> 10/14/2005, leader, 4
> 10/15/2005, employee, 5
> Thanks for any suggestions.|||Or where you looking for something like this ?
--
--
DROP TABLE Table1
CREATE TABLE Table1
(
[date] datetime,
leader_count int,
employee_count int,
manager_count int
)
INSERT INTO Table1 VALUES('10/14/2005', 4 ,5 ,5)
SELECT * FROM Table1
DROP TABLE NewTable
CREATE TABLE NewTable
(
[date] datetime,
Type char(10),
[count] int
)
INSERT INTO NewTable ([Date],Type,[count]) SELECT
[date],'Leader',leader_count FROM Table1
INSERT INTO NewTable ([Date],Type,[count]) SELECT
[date],'Employee',employee_count FROM Table1
INSERT INTO NewTable ([Date],Type,[count]) SELECT
[date],'Manager',manager_count FROM Table1
Go
SELECT * FROM NewTable
--
but try not to use so many reserved words
"David J. Cartwright" <davidcartwright@.hotmail.com> wrote in message
news:eliQgmO$FHA.140@.TK2MSFTNGP12.phx.gbl...
> what do you mean transpose, how about using a view ?
> "AshleyT" <AshleyT@.discussions.microsoft.com> wrote in message
> news:07EF85C2-5F94-4E60-86B6-A9713160D21C@.microsoft.com...
>>I have a table that has :
>> date, leader_count, employee_count, manager_count
>> 10/14/2005, 4 ,5 ,5
>> Any idea how I can almost transpose the table to create a table that
>> looks
>> like:
>> date, type, count
>> 10/14/2005, leader, 4
>> 10/15/2005, employee, 5
>> Thanks for any suggestions.
>|||PERFECT! THANK YOU VERY MUCH.
"David J. Cartwright" wrote:
> Or where you looking for something like this ?
> --
> --
> DROP TABLE Table1
> CREATE TABLE Table1
> (
> [date] datetime,
> leader_count int,
> employee_count int,
> manager_count int
> )
> INSERT INTO Table1 VALUES('10/14/2005', 4 ,5 ,5)
> SELECT * FROM Table1
> DROP TABLE NewTable
> CREATE TABLE NewTable
> (
> [date] datetime,
> Type char(10),
> [count] int
> )
> INSERT INTO NewTable ([Date],Type,[count]) SELECT
> [date],'Leader',leader_count FROM Table1
> INSERT INTO NewTable ([Date],Type,[count]) SELECT
> [date],'Employee',employee_count FROM Table1
> INSERT INTO NewTable ([Date],Type,[count]) SELECT
> [date],'Manager',manager_count FROM Table1
> Go
> SELECT * FROM NewTable
> --
> but try not to use so many reserved words
> "David J. Cartwright" <davidcartwright@.hotmail.com> wrote in message
> news:eliQgmO$FHA.140@.TK2MSFTNGP12.phx.gbl...
> > what do you mean transpose, how about using a view ?
> >
> > "AshleyT" <AshleyT@.discussions.microsoft.com> wrote in message
> > news:07EF85C2-5F94-4E60-86B6-A9713160D21C@.microsoft.com...
> >>I have a table that has :
> >>
> >> date, leader_count, employee_count, manager_count
> >> 10/14/2005, 4 ,5 ,5
> >>
> >> Any idea how I can almost transpose the table to create a table that
> >> looks
> >> like:
> >>
> >> date, type, count
> >> 10/14/2005, leader, 4
> >> 10/15/2005, employee, 5
> >>
> >> Thanks for any suggestions.
> >
> >
>
>

No comments:

Post a Comment