Monday, February 20, 2012

Multiple rows into one row

Hello I am wondering if this is possible.

I have a two tables one contains Plan information and another that
contains product information about the plan

ex:
Plan table
PlanID Plan_name
1 a
2 b

Product Table
ProductID PlanID Comments
1 1 com1
2 1 com2
3 1 com3

What I am looking to do if possible would be the following

Plan Product1 Comments1 Product2 Comments2
1 1 com1 2 com2

I am wondering down what path I should explore cause I am new to this.
I am using sql 2005Chicagoboy27 wrote:

Quote:

Originally Posted by

Hello I am wondering if this is possible.
>
I have a two tables one contains Plan information and another that
contains product information about the plan
>
ex:
Plan table
PlanID Plan_name
1 a
2 b
>
Product Table
ProductID PlanID Comments
1 1 com1
2 1 com2
3 1 com3
>
What I am looking to do if possible would be the following
>
Plan Product1 Comments1 Product2 Comments2
1 1 com1 2 com2
>
>
I am wondering down what path I should explore cause I am new to this.
I am using sql 2005


Take a look at PIVOT in Books Online. Also Itzik Ben-Gan has articles
on PIVOT in the last two issues of SQL Server Magazine. www.sqlmag.com
--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/...US,SQL.90).aspx
--|||Thanks I will explore that option...

David Portas wrote:

Quote:

Originally Posted by

Chicagoboy27 wrote:

Quote:

Originally Posted by

Hello I am wondering if this is possible.

I have a two tables one contains Plan information and another that
contains product information about the plan

ex:
Plan table
PlanID Plan_name
1 a
2 b

Product Table
ProductID PlanID Comments
1 1 com1
2 1 com2
3 1 com3

What I am looking to do if possible would be the following

Plan Product1 Comments1 Product2 Comments2
1 1 com1 2 com2

I am wondering down what path I should explore cause I am new to this.
I am using sql 2005


>
Take a look at PIVOT in Books Online. Also Itzik Ben-Gan has articles
on PIVOT in the last two issues of SQL Server Magazine. www.sqlmag.com
>
--
David Portas, SQL Server MVP
>
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
>
SQL Server Books Online:
http://msdn2.microsoft.com/library/...US,SQL.90).aspx
--

No comments:

Post a Comment