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.
| Author |
Topic |
|
d473566
Starting Member
23 Posts |
Posted - 2002-03-15 : 23:19:22
|
| I have searched the forums and have not seen this asked yet, so hopefully I am not duplicating another post.Here is the problem. I have one table of records, joined to a pivot table, joined to a table that holds descriptions of that record. (The table of records is also joined to another pivot table, joined to descriptions of funding, but I haven't gone there yet!) What I want to do is have it output (in Cold Fusion, not that this is a necessary detail) the university name first, then all of the group_names, then all of the desriptive_names.Is this possible, or do I need to do some funky Cold Fusion programming.Here is the code I have come up with so far:SELECTtbl_benefit_records.id,tbl_benefit_records.university_id AS univID,tbl_benefit_types.benefit_name,tbl_universities.university,tbl_benefit_groups.group_name,tbl_descriptives.id AS descriptID,tbl_descriptives.descriptive_name,tbl_record_descriptives.additional_infoFROM tbl_benefit_recordsINNER JOIN tbl_benefit_types ON tbl_benefit_records.benefit_type_id = tbl_benefit_types.idINNER JOIN tbl_universities ON tbl_benefit_records.university_id = tbl_universities.idINNER JOIN tbl_benefit_emp_groups ON tbl_benefit_records.id = tbl_benefit_emp_groups.record_idINNER JOIN tbl_benefit_groups ON tbl_benefit_groups.id = tbl_benefit_emp_groups.group_idLEFT OUTER JOIN tbl_record_descriptives ON tbl_record_descriptives.record_id = tbl_benefit_records.idLEFT JOIN tbl_descriptives ON tbl_descriptives.id = tbl_record_descriptives.benefit_descript_idAnd the results:ID|univID|benefit_name|university|group_name|descriptID|descriptive_name|additional_info20|2|Medical|U of O|Faculty|29|CPP Integration|cpp test20|2|Medical|U of O|Faculty|30|Indexing Formula|indexing test20|2|Medical|U of O|Librarian|29|CPP Integration|cpp test20|2|Medical|U of O|Librarian|30|Indexing Formula|indexing testWhat I want, is the result to be formatted like:University: U of Ogroup_names: faculty,librariandescriptive_name: CPP integration, Indexing FormulaIs this even a GROUP BY issue?Hope I have explained the problem thoroughly. Thanks for any help! |
|
|
Merkin
Funky Drop Bear Fearing SQL Dude!
4970 Posts |
Posted - 2002-03-16 : 00:14:52
|
| HiThis is more a reporting thing, it is doable in SQl, you need to build a temp table or 2 and do some funky "coalesce" (search the site for that) -ing of dataYou might be better off doing it in Cold Fusion, for every row, look to see if the univerity name is that same as the last and either append to the current line or add a new one.Damian |
 |
|
|
d473566
Starting Member
23 Posts |
Posted - 2002-03-18 : 13:15:23
|
| That's what I thought, since it was pulling all the info correctly, just not sorting it the way I want. I was hoping for a single query answer. Unfortunately, right now it is 3-4 queries per record to get the info the way I want, which is not very efficient. |
 |
|
|
|
|
|
|
|