Qurey output display in different format

Hi

I have a  simple query  which gives output as on column . Is there a way to split the output into multiple columns.

Select Distinct MACH  From Test_table with(nolock)
Where Left(Mach,1) = 'T'or Left(Mach,1) = 'U' or Left(Mach,1) = 'X'

Result :

====

Mach

T01
T02
T03
U01
U02
U03
X01
X02
X03

I want the output in this format

=====
Mach1    Mach2     Mach3
T01         U01        X01
T02         U02        X02
T03         U03        X03

Please help me out ..:)




coolnit74Asked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
select 'T' + t.value as mach1, 'U' + u.value as mach2, 'X' + x.value as mach3
from ( Select distinct substring(Mach,2,50) as Value ) as L
left join ( Select substring(Mach,2,50) as Value From Test_table with(nolock) Where Left(Mach,1) = 'T' ) as t
  on t.value = l.value
left join ( Select substring(Mach,2,50) as Value From Test_table with(nolock) Where Left(Mach,1) = 'U' ) as u
  on u.value = l.value
left join (Select substring(Mach,2,50) as Value From Test_table with(nolock) Where Left(Mach,1) = 'X'  ) as x
  on x.value = l.value
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
how are the values related, will it be Tnn, Unn and Xnn , with nn each time on the same row?
0
 
coolnit74Author Commented:
yes   nn eachtime on the same row
0
 
coolnit74Author Commented:
Excellentoooooo…   thank you :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.