Click here to Skip to main content
15,886,797 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm modifying a stored procedure which populates a MyInsights report. That M.I report is opened as a drill to detail report from a 3D Interface.

The concatentation is intended to ensure that a unique row is returned. For example, if I want to return results in the following format:

ID | LName | Vehicle |
1 | Doe | Honda , Ford |
2 | Johnson | BMW, Audi |

What I don't want to return is the following


ID | LName | Vehicle |
1 | Doe | Honda |
2 | Doe | Ford |
3 | Johnson | BMW |
4 | Johnson | Audi |

The SQL being used is listed: (Please note the above results are not directly related to the SQL listed)

Cross Apply
	(
	select REPLACE(
	(
	select dsg.ShortDescription +', '
	from Final.FactStudentGroups fsg
		join final.dimstudentgroup dsg	
			on fsg.StudentGroupKey = dsg.studentgroupkey
	where fsg.VersionKey = 1
	and fsg.TermSourceKey = SDDT.TermSourceKey
	and fsg.EmployeeID = SDDT.EmployeeID
	and fsg.VersionKey = SDDT.VersionKey
	
	FOR XML PATH('')
	),'&','&') as SGroup -- Not sure why code to the left is commented but it should not be. 
	)StudentGroup



As of right now I'm returning data that I don't even recognize from my dsg.Table which is the table I'm attempting to pull data from.

Any information is appreciated! Thanks in advance.
Posted
Comments
phil.o 15-Sep-15 23:02pm    
So, you want to get cars and manufacturer names from a set of tables related to students, groups and employees?

If you want to describe your problem well, you need to be honest and provide the real facts you have so far. In your question, either the results you wrote are not those that you really expect, or the SQL code you show is not the code you really have. And neither make sense.
Member 11820531 16-Sep-15 10:02am    
No the example output was used only to illustrate how I want my results to look. Realistically, I am working with students, groups, and employees. (i.e. The line where I wrote: Please note the above results are not directly related to the SQL listed)

The code I pasted in there is also code that I am actually using. You probably don't understand my question as the information available to you is not enough for you to answer my question.

Thanks for your input.
Charlemagne Gustilo 30-Sep-15 2:10am    
Hi, are you collecting the list of records as a single record? Check COALESCE function to handle that. Below is a sample.

DECLARE @SQL VARCHAR(8000)

SELECT @SQL=COALESCE(@SQL,'')+' '+RTRIM(FIELD)+ ', '
FROM TABLE

SELECT @SQL

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900