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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Crosstab Query

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-06-08 : 08:50:39
Mark writes "Let me start by explaining what I need. I am using Windows 2000 Server with SQL2000, and I have approx 10 tables that I need to query, each with either a child or grandchild relationship with the main table.

For example:
Table A - RecordID, RecordName
Table B - SecondID, RecordID
Table C - SecondID, NewName
Table D - ThirdID, RecordID
Table E - ThirdID, DifferentName

I need to run a crosstab query that would appear similar to this

RecordID - RecordName - NewName(value) - DifferentName(Value)

The problem I am having is that I only want to show the Record From Table A once, and because it is set up to a one to many relationship with the other tables (Table B and Table D) I will get a result set like this:

RecordID - RecordName - NewName(value1) - DifferentName(Value1)
RecordID - RecordName - NewName(value2) - DifferentName(Value2)
RecordID - RecordName - NewName(value3) - DifferentName(Value3)

The values will sometimes be null (which is ok, and what I want it to do, however I do not want the rows to repeat if the Record ID is the same.

Is it possible to combine (or Concat) the similar records into a string?

For example:

RecordID - RecordName - NewName(value1, value2, value3) - DifferentName(Value1,value2, value3)

I have been knocking myself out over this and cannot seem to find the solution."
   

- Advertisement -