SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Old Forums
 CLOSED - General SQL Server
 Cross-tab or Pivot... How can I do it?
 Forum Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

AskSQLTeam
Ask SQLTeam Question

USA
0 Posts

Posted - 03/17/2006 :  08:26:22  Show Profile  Visit AskSQLTeam's Homepage
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)

Singapore
17658 Posts

Posted - 03/17/2006 :  08:34:39  Show Profile
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




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
  Previous Topic Topic Next Topic  
 Forum Locked
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000