Hi,I'm in the process of creating a report for one of our clients but I'm stumped on one of the requirements. So what I'm trying to do makes sense I'll provide the following tables and data:CREATE TABLE #CASES ( CASEID INT, CASEREF VARCHAR(10))CREATE TABLE #CASENAME ( CASEID INT, NAMENO INT, NAMETYPE CHAR(1))CREATE TABLE #NAME ( NAMENO INT, NAMECODE VARCHAR(100))INSERT INTO #CASES VALUES (1, 'P01')INSERT INTO #CASENAME VALUES (1, 001, 'O')INSERT INTO #CASENAME VALUES (1, 002, 'O')INSERT INTO #NAME VALUES (001, 'OWNER 1')INSERT INTO #NAME VALUES (002, 'OWNER 2')SELECT C.CASEREF, N.NAMECODEFROM #CASES CINNER JOIN #CASENAME CN ON CN.CASEID = C.CASEID AND CN.NAMETYPE = 'O'INNER JOIN #NAME N ON N.NAMENO = CN.NAMENO
When I run this query two rows are returned for the same case but our client only wants one row per case. I'm not sure if/how I can get the name of the second owner (if there is one) to be combined in a column with the first owner (there should always be one).Any ideas how I could go about this?