Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7067887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:15:21+00:00 2026-05-28T05:15:21+00:00

I have a table which looks something like Event ID Date Instructor 1 1/1/2000

  • 0

I have a table which looks something like

Event ID  Date       Instructor
1         1/1/2000    Person 1
1         1/1/2000    Person 2

Now what I want to do is return this data so that each event is on one row and the Instructors are all in one column split with a <br> tag like 'Person 1 <br> Person 2'

Currently the way I have done this is to use a function

CREATE FUNCTION fnReturnInstructorNamesAsHTML
(
    @EventID INT
)
RETURNS VARCHAR(max)
BEGIN

    DECLARE @Result VARCHAR(MAX)

    SELECT 
        @result = coalesce(@result + '<br>', '') + inst.InstructorName 
    FROM
        [OpsInstructorEventsView]   inst
    WHERE
        inst.EventID = @EventID

    RETURN @result


END

Then my main stored procedure calls it like

   SELECT 
        ev.[BGcolour], 
        ev.[Event] AS name, 
        ev.[eventid] AS ID, 
        ev.[eventstart], 
        ev.[CourseType], 
        ev.[Type], 
        ev.[OtherType], 
        ev.[OtherTypeDesc], 
        ev.[eventend], 
        ev.[CourseNo], 
        ev.[Confirmed], 
        ev.[Cancelled], 
        ev.[DeviceID] AS resource_id, 
        ev.Crew, 
        ev.CompanyName , 
        ev.Notes,
        dbo.fnReturnInstructorNamesAsHTML(ev.EventID) as Names
    FROM 
        [OpsSimEventsView] ev
    JOIN
        [OpsInstructorEventsView]   inst
    ON
        ev.EventID = inst.EventID 

This is very slow, im looking at 4seconds per call to the DB. Is there a way for me to improve the performance of the function? Its a fairly small function so im not sure what I can do here, and I couldnt see a way to work the COALESCE into the SELECT of the main procedure.

Any help would be really appreciated, thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:15:21+00:00Added an answer on May 28, 2026 at 5:15 am

    You could try something like this.

    SELECT 
        ev.[BGcolour], 
        ev.[Event] AS name, 
        ev.[eventid] AS ID, 
        ev.[eventstart], 
        ev.[CourseType], 
        ev.[Type], 
        ev.[OtherType], 
        ev.[OtherTypeDesc], 
        ev.[eventend], 
        ev.[CourseNo], 
        ev.[Confirmed], 
        ev.[Cancelled], 
        ev.[DeviceID] AS resource_id, 
        ev.Crew, 
        ev.CompanyName , 
        ev.Notes,
        STUFF((SELECT '<br>'+inst.InstructorName
               FROM [OpsInstructorEventsView]   inst
               WHERE ev.EventID = inst.EventID
               FOR XML PATH(''), TYPE).value('.', 'nvarchar(max)'), 1, 4, '') as Names
    FROM 
        [OpsSimEventsView] ev
    

    Not sure why you have joined OpsInstructorEventsView in the main query. I removed it here but if you needed you can just add it again.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables which looks something like this Table Queue int ID; string
I have jQuery code which looks something like this on Button1 Click $('table.result_grid tbody
I have a table which looks like this: <table id='t'> <thead> .... </thead> <tbody
I have this mysql table called comments which looks like this: commentID parentID type
i have a table which looks similar to this <asp:TableRow><asp:TableCell>Question 1</asp:TableCell><asp:TableCell ID =Question1Text></asp:TableCell></asp:TableRow> <asp:TableRow><asp:TableCell
i have a table (tbl_world) which look like this id | first_name | last_name
I have a couple of tables which look like this Table 1 user_id |
I have a table which is full of arbitrarily formatted phone numbers, like this
I have a data-structure (in plist) that looks something like this: What i have
I have a join in a oracle query which looks like: FROM eiv.table1 eiv.table2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.