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
 General SQL Server Forums
 New to SQL Server Programming
 how to select similar records?

Author  Topic 

ozkan
Starting Member

3 Posts

Posted - 2010-07-06 : 07:46:23
hi,
I've a table as follows:

Name date location
A 07.07.2010 usa
B 07.07.2010 usa
C 07.07.2010 usa

Column name in the different records but the records are the same in the other column.
On my program that I want it to appear in the following table.

Name date location
A,B,C 07.07.2010 usa

With how I have to take a SQL query?
Thanks.

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-07-06 : 08:14:04
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81254

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

slimt_slimt
Aged Yak Warrior

746 Posts

Posted - 2010-07-06 : 08:15:15
try this:


create table test123
(name char(1)
,date smalldatetime
,location varchar(10)
)

insert into test123
select 'A', '2010/07/07', 'usa' union all
select 'B', '2010/07/07', 'usa' union all
select 'C', '2010/07/07', 'usa'


select
date
,location
,stuff((select ',' + a.name
from test123 as a
where
a.date = b.date
and a.location = b.location
order by a.name
for xml path('')),1,1,'') as [all]

from test123 as b
group by date, location
order by date, location

Go to Top of Page

ozkan
Starting Member

3 Posts

Posted - 2010-07-07 : 09:14:31
thanks slimt_slimt for your answer
Well, Can I apply that select expression in MS Access?
I'm using it.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-07-08 : 03:17:15
Post your question at Access Forum

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -