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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 sql select help please
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sebastian11c
Posting Yak Master

125 Posts

Posted - 05/23/2012 :  17:54:05  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

USA
1610 Posts

Posted - 05/23/2012 :  18:25:23  Show Profile  Click to see yosiasz's MSN Messenger address  Reply with Quote
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
Flowing Fount of Yak Knowledge

USA
1610 Posts

Posted - 05/23/2012 :  18:33:35  Show Profile  Click to see yosiasz's MSN Messenger address  Reply with Quote

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



<><><><><><><><><><><><><><><><><>
If you don't have the passion to help people, you have no passion

Edited by - yosiasz on 05/23/2012 18:35:27
Go to Top of Page

sebastian11c
Posting Yak Master

125 Posts

Posted - 05/24/2012 :  09:12:02  Show Profile  Reply with Quote
brilliant code ,,,

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

yosiasz
Flowing Fount of Yak Knowledge

USA
1610 Posts

Posted - 05/24/2012 :  09:33:10  Show Profile  Click to see yosiasz's MSN Messenger address  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 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