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
 Columns in subreport

Author  Topic 

vree
Starting Member

30 Posts

Posted - 2005-12-20 : 16:10:37
SQL Server DB; using Access ADP frontend; i have a report that shows companies; and a subreport that shows all the employees for that company and the committees they serve on.

There is a one to many between Committee and MemberContact

Committee
Marketing
Customer Service
Membership

I would like to display in a subreport info like this
Joe Blow - Marketing, Customer Service
Jane Blow - Membership, Marketing

Which is a concatonation of the fields on the one side of the relationship.
Possible? help appreciated.

rrb
SQLTeam Poet Laureate

1479 Posts

Posted - 2005-12-20 : 18:25:16
vree

there's no easy answer. you need to write code to do the concatenation. In access you can cheat and write code in the report.On_Print() event to compile the concatenated string for each person. Pretty straight forward - open a recordset to the person's committees and loop through to build up the string - then set the value of the report control to be the resulting concatenation. Easy.

Something like (using DAO)
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
dim db as DAO.database
dim rst as DAO.recordset
dim sql as String
dim sCommitteeList as String

sql = "select c.committeename from Committee c left join MemberContact m on m.committeeid = c.id where m.id = " & Me.ID.value
set db = currentdb()
set rst = db.Openrecordset(sql)

do while not rst.EOF
'concatenate
if len(sCommitteeList ) = 0 then
sCommitteeList = Nz(rst.Fields("committeename"),"")
else
sCommitteeList = sCommitteeList & "," & Nz(rst.Fields("committeename"),"")
end if

rst.Movenext
loop
rst.Close

set rst = nothing
set db = nothing

Me.txtCommitteeList.value = sCommitteeList

End Sub
Not fast but it will work OK.

The most elegant solution would be to write a pass through query which does the same concatenating in T-SQL on your SQL Server. This may require you to redesign your report a little... you could check out this

post back if you need more help

--
I hope that when I die someone will say of me "That guy sure owed me a lot of money"
Go to Top of Page
   

- Advertisement -