3 Replies - 655 Views - Last Post: 27 March 2009 - 07:18 AM Rate Topic: -----

#1 gymratz  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 129
  • Joined: 18-October 07

SQL Query, Strange way of Grouping...

Posted 26 March 2009 - 11:05 AM

Each "Travel_Visit" has a start/end time, and person doing the visit (Emp_ID).
I have a foreign key of "Travel_ID" in this table, as each "Travel" can have multiple visits.

I need to pull a summary that takes the min date, max date, and lists all employees related.

I have the first part:

Select
	Min(TV.Start_DateTime) as [Start],
	Max(TV.End_DateTime) as [End]
From Travel_Visits as TV
Where
	TV.Travel_ID = '11'


But how do I list all employees in the same column separated by commas?
The query should only return a single row and 3 columns (the two I have above, and the third with a list of employees.

Is This A Good Question/Topic? 0
  • +

Replies To: SQL Query, Strange way of Grouping...

#2 xerxes333  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 31
  • View blog
  • Posts: 504
  • Joined: 05-July 07

Re: SQL Query, Strange way of Grouping...

Posted 27 March 2009 - 05:39 AM

I don't think its possible without using a sub-select to build the string
Was This Post Helpful? 0
  • +
  • -

#3 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5775
  • View blog
  • Posts: 12,587
  • Joined: 16-October 07

Re: SQL Query, Strange way of Grouping...

Posted 27 March 2009 - 06:31 AM

View Postgymratz, on 26 Mar, 2009 - 12:05 PM, said:

But how do I list all employees in the same column separated by commas?


Nope. Database store and retrieve data, they don't obfuscate it for our viewing pleasure; that's what report writers are for.

You could write a user defined function to return a string, given an id. There's also a trick with SQL Server using coalesce, but you're not going to get with just a select.
Was This Post Helpful? 0
  • +
  • -

#4 gymratz  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 129
  • Joined: 18-October 07

Re: SQL Query, Strange way of Grouping...

Posted 27 March 2009 - 07:18 AM

That is what I was afraid of - guess I get the data with SQL and then use vb.net to make it look pretty :).

Thanks guys!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1