Home All Groups Group Topic Archive Search About

Display rows as columns

Author
19 Aug 2005 12:00 PM
Renjith
Hi

i have a table like

Id , ColumnName   group
1    C1                   1
2    C2                   1
3    C3                   2

these columns are mapped to another table like

Id C1 C2 C3.....

so the columns tht must be selected from the transaction table differs
according to the group in the mapping table.

so can i  write a query to get the data from transaction table for a group
in mapping table.

I DONT WANT TO USE DYNAMICALLY CREATED QUERY..

plz send the solution as the client is waiting

Renjith

Author
19 Aug 2005 12:12 PM
Chandra
Hi Renjith

Probably you can use CASE statement for this. This is similar to DECODE
statement available in Oracle.

Please post the expected result so that we can give u a solution

--
best Regards,
Chandra
http://chanduas.blogspot.com/
http://www.SQLResource.com/
---------------------------------------



Show quote
"Renjith" wrote:

> Hi
>
> i have a table like
>
> Id , ColumnName   group
> 1    C1                   1
> 2    C2                   1
> 3    C3                   2
>
> these columns are mapped to another table like
>
> Id C1 C2 C3.....
>
> so the columns tht must be selected from the transaction table differs
> according to the group in the mapping table.
>
> so can i  write a query to get the data from transaction table for a group
> in mapping table.
>
> I DONT WANT TO USE DYNAMICALLY CREATED QUERY..
>
> plz send the solution as the client is waiting
>
> Renjith
>
Author
19 Aug 2005 12:37 PM
Aaron Bertrand [SQL Server MVP]
> Id , ColumnName   group
> 1    C1                   1
> 2    C2                   1
> 3    C3                   2
>
> these columns are mapped to another table like
>
> Id C1 C2 C3.....

Sounds like a cross-tab / pivot.
http://www.aspfaq.com/2462

> plz send the solution as the client is waiting

So why is the client paying YOU?  I wonder what the client would think if
they saw your post and recognized you as their consultant?
Author
19 Aug 2005 12:56 PM
Renjith
Hi

i need the result as
when i select group = 1

Id     C1    C2 

the value of c1 , c2 will be transaction table

when i select group = 2

Id     C3

the value of C3 will be transaction table

Renjith



Show quote
"Renjith" wrote:

> Hi
>
> i have a table like
>
> Id , ColumnName   group
> 1    C1                   1
> 2    C2                   1
> 3    C3                   2
>
> these columns are mapped to another table like
>
> Id C1 C2 C3.....
>
> so the columns tht must be selected from the transaction table differs
> according to the group in the mapping table.
>
> so can i  write a query to get the data from transaction table for a group
> in mapping table.
>
> I DONT WANT TO USE DYNAMICALLY CREATED QUERY..
>
> plz send the solution as the client is waiting
>
> Renjith
>
Author
19 Aug 2005 1:06 PM
Aaron Bertrand [SQL Server MVP]
> i need the result as
> when i select group = 1
>
> Id     C1    C2
>
> the value of c1 , c2 will be transaction table
>
> when i select group = 2
>
> Id     C3
>
> the value of C3 will be transaction table


http://www.aspfaq.com/5006

AddThis Social Bookmark Button