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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 sql select help please

Author  Topic 

sebastian11c
Posting Yak Master

129 Posts

Posted - 2012-05-23 : 17:54:05
hi there


i have a table called "cars"


idcar make line
1 audi a4
2 audi a6
3 audi s6
4 audi a8
5 bmw 318
6 bmw 320
7 bmw 325



i need to do a query , with this result

columns ( make , lines ( all the lines with the same make without the line "a4" horizontal)

make(varchar) lines (varchar (max))
audi a6 s6 a8
bmw 318 320 325


many many thanks in advanced,,

thank for your help


yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2012-05-23 : 18:25:23
Senor Sebastian

Please provide DDL and DML

<><><><><><><><><><><><><><><><><>
If you don't have the passion to help people, you have no passion
Go to Top of Page

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2012-05-23 : 18:33:35
[code]
declare @sebastian table(dcar int, make varchar(25), line varchar(25))

insert into @sebastian
select 1, 'audi', 'a4'
union
select 2, 'audi', 'a6'
union
select 3, 'audi', 's6'
union
select 4, 'audi', 'a8'
union
select 5, 'bmw', '318'
union
select 6, 'bmw', '320'
union
select 7, 'bmw', '325'


select *
from @sebastian


select make,

stuff(

(

select distinct ',[' + line + ']'

from @sebastian s2
where s2.make = s1.make
AND line <> 'a4'


for xml path('')


),1,1,'')

from @sebastian s1
group by make

[/code]

<><><><><><><><><><><><><><><><><>
If you don't have the passion to help people, you have no passion
Go to Top of Page

sebastian11c
Posting Yak Master

129 Posts

Posted - 2012-05-24 : 09:12:02
brilliant code ,,,

thank you so much yosiasz
thanks for always helping
Go to Top of Page

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2012-05-24 : 09:33:10
denada. learning from great minds right here on this site

<><><><><><><><><><><><><><><><><>
If you don't have the passion to help people, you have no passion
Go to Top of Page
   

- Advertisement -