Solved

Show multiple records in one field using SQL

Posted on 2007-04-03
3
174 Views
Last Modified: 2010-03-19
I'm running an Access front end and a SQL backend.  I have tblDaily and tblRooms.  There is a one to many relationship.  The fields in tblDaily can have multiple rooms.  I want to display 3 fields (Facility, Elevation and Area) from tblDaily but also the multiple rooms from tblRooms all in one field on a report.
Ex: Facility, Elevation, Area, Rm1, Rm2, Rm3

I found Function fncConcat() example code on Expert Exchange but it doesn't work for me because my backend is SQL Server.  Can anyone offer any other suggestions?  Please?
0
Comment
Question by:BobRosas
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
dready earned 500 total points
ID: 18847624
I am not sure wether this will work, but give this a try

select facility, elevation, area, (select concat(rooms) from tblRooms where FID_Daily = tblDaily.id) from tblDaily

(Dont know what your tblRooms looks like, i assumed it has a rooms field and a foreign key called FID_Daily... of course you will have to replace it with real fieldnames)
0
 

Author Comment

by:BobRosas
ID: 18851601
I could really use more help with the SQL statement.  I forgot to include tblTestPerformed which links tblDaily and tblRooms.  Also tblWorkRelease has the field “facility” which I need.  
The following is the SQL code I’m trying but I get the error “Syntax error in query expression ‘(select concat (tblRooms.RoomNo))’.  

SELECT tblWorkRelease.Facility, tblDaily.Elevation, tblDaily.Area, (select concat (tblRooms.RoomNo))
FROM ((tblWorkRelease INNER JOIN tblDaily ON tblWorkRelease.WorkReleaseId = tblDaily.WorkReleaseId) INNER JOIN tblTestsPerformed ON tblDaily.QCReportNo = tblTestsPerformed.QCReportNo) INNER JOIN tblRooms ON tblTestsPerformed.TestDescId = tblRooms.TestDescId
WHERE (((tblDaily.QCReportNo)=2947))
ORDER BY tblRooms.RoomNo;
Thanks!
0
 

Author Comment

by:BobRosas
ID: 18865416
I don't think concat works with SQL but I appreciate that you responded.  I will try reposting my question.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question