Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Old Forums
 CLOSED - General SQL Server
 Cross-tab or Pivot... How can I do it?

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-03-17 : 08:26:22
Julio Cesar writes "My English is poor. I hope you can understand me.

I have two Tables related each one.

TABLE A
(ID) (NAME) Cols...
01 VALVES
02 PIPING

TABLE B
(ID) (MODIFIER) (ID_NAME) Cols
01 BALL 01
02 CHECK 01
03 GATE 01
04 PIPE COATED 02

If I do a SELECT with the two Tables I get the following results.

(ID) (NAME) (MODIFIER)
01 VALVES BALL
01 VALVES CHECK
01 VALVES GATE
02 PIPING PIPE COATED

My question is.. Is there any way to format this output to the following?...

(ID) (NAME) (MODIFIER_1) (MODIFIER_2) (MODIFIER_3)
01 VALVES BALL CHECK GATE
02 PIPING PIPE COATED

Thanks in advance..."

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-03-17 : 08:34:39
[code]select a.ID, a.Name,
max(case when b.ID = '01' then b.MODIFIER else '' end) as [MODIFIER_1],
max(case when b.ID = '02' then b.MODIFIER else '' end) as [MODIFIER_2],
max(case when b.ID = '03' then b.MODIFIER else '' end) as [MODIFIER_3]
from TableA a inner join TableB b
on a.ID = b.ID_NAME
group by a.ID, a.Name[/code]



KH

Choice is an illusion, created between those with power, and those without.
Concordantly, while your first question may be the most pertinent, you may or may not realize it is also the most irrelevant

Go to Top of Page
   

- Advertisement -