Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 9th, 2004, 10:59 AM
Authorized User
 
Join Date: Jun 2003
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default Query Help

Having a brain fart and I know this is simple but I’ve already wasted a couple hours – so I was wondering if someone could help.

Example Source Table:
Id: Company: StatesCovered:
1 ABC WA
2 Car Toys IL
3 Car Toys WA
4 Car Toys FL
5 Car Toys NY
6 Frys CA
7 Frys WA
8 Frys KY
9 Bobs NY
10 Bobs KY

Result Set Desired:
Company: StatesCovered:
ABC WA
Car Toys IL, WA, FL, NY
Frys CA, WA, KY
Bobs NY, KY
__________________
_________________________
Joe Horton
Database Developer / Software Engineer
WISHA/Legal Services Software Development
Department of Labor and Industries
Voice (360) 902-5928 fax (360) 902-6200
 
Old June 9th, 2004, 09:45 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Hortoristic,

This has been discussed many times in the other forum(SQL LANGUAGE) under different topics. You may take a look at it.

Aggregate Concatenation

How to Concatenate Data

But IMO, the best thing possible to get there, is to be done from the frontend. SQL is not the right thing to do such formatting.

Logic for doing this in the frontend could be,[list=1][*]Have 2 frontend variables Company and StatesCovered[*]
Code:
Select Company, StatesCovered from YOURTABLE Order by Company
[*]Get that in a recordset and loop through till END of it[*]When the Company value is the same for every next record, keep storing the StatesCovered Value in a String seperated by Commas[*]Everytime Company value changes display the Company Name and StatesCovered String on the page and reset the StatesCovered String to EMPTY
</ol id="1">

This way you can achieve that. But I am not sure, if you intend to do this in frontend.
Hope that helps.
Cheers!

_________________________
-Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
Output Query to txt file from SQL Query everest SQL Server 2005 4 November 22nd, 2007 01:49 AM
how to make a query from an existing query raport SQL Language 3 November 13th, 2006 08:59 PM
I solved insert query.now see this Update Query. [email protected] VB.NET 2002/2003 Basics 2 September 21st, 2006 12:48 AM
Syntax error in query. Incomplete query clause. dispickle ADO.NET 3 April 16th, 2004 01:04 PM
Error on Make-Table Query In Union Query rylemer Access 1 August 20th, 2003 07:42 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.