SQL Server XML output with dynamic SQL

marmz

New Member
I'm faced with a little question on xml output.I need to get xml structure like this:and here is my procedure, it'll list all the employees and some of their personal infobased on input.\[code\]CREATE PROC getDeptEmployees(@deptList varchar(500))ASBEGINSET NOCOUNT ON DECLARE @Query varchar(600)SET @Query = 'SELECT department.DEPARTMENT_ID [f_Department_ID], department.DEPARTMENT_NAME [f_Department_name],dp.Employee_id [f_Employee_ID], dp.First_name [f_First_Name], dp.Last_Name [f_Last_name], dp.Email [f_email], dp.Salary [f_salary]FROM dbo.Employees dp JOIN DEPARTMENTS department ON dp.DEPARTMENT_ID = department.DEPARTMENT_IDWHERE dp.Department_id IN (' + @deptList + ') for XML AUTO, ROOT(''table'')'EXEC(@Query) ENDGO\[/code\]What I get is herebut I still can't figure out how to add the DPR node.Thank you
 
Back
Top