Solved

Dynamic filename path in stored procedure

Posted on 2010-08-30
2
241 Views
Last Modified: 2012-05-10
Hi, I am trying to set the file path of my xml output file in my stored procedure to be dynamic.  I can't seem to get it to work; not sure what I'm doing wrong. I keep getting the error "Error writing to file Illegal characters in path." I've attached my code.
ALTER PROCEDURE [dbo].[spResumeXMLGeneration] 
@username varchar(50),
@profile varchar(50)

	AS
Declare @xml nvarchar(max)
Declare @filepath  nvarchar(max)
Set @filepath = 'C:\"' + @username + '".xml'


Set @xml =
(
Select 
employee.ProjectName,
employee.Employeeno,
employee.EmployeeName,
employee.Work_Summary,
employee.Accreditation_Affliation,
employee.PE_Certification,
employee.LEED_Certification,
employee.CPD_Certification,
employee.RoleonProject,
--subquery for Projects
(SELECT 
ProjectName,
Location

	
	FROM 
	Profiles_Employee_Projects_XML as project
	
	WHERE
	Username = employee.Username and
	
	Profile = employee.Profile and
	EmployeeID = employee.EmployeeID and 
	project.IncludeonResume = 1
	order by project.Sort_Order
	
	
	
	FOR
		XML PATH ('Projects'),TYPE -- Column is typed so it nests as XML, not text.
	)	
		,


--subquery for Education
(SELECT 
School_Facility,
Degree_Completed,
Completion_Year

	
	FROM 
	Profiles_Employee_Education as education
	
	WHERE
	Username = employee.Username and
	
	Profile = employee.Profile and
	EmployeeID = employee.EmployeeID 
	
	 
	order by education.Completion_Year

	
	FOR
		XML PATH ('Education'),TYPE -- Column is typed so it nests as XML, not text.
	)	
		,
		--subquery for Education

(SELECT 
ReferenceTitle,
ReferenceName,
ReferenceCompany,
ReferenceEmail,
ReferencePhone

	
	FROM 
	Profiles_Employee_References as reference
	
	WHERE
	Username = employee.Username and
	
	Profile = employee.Profile and
	EmployeeID = employee.EmployeeID 
	

	
	FOR
		XML PATH ('References'),TYPE -- Column is typed so it nests as XML, not text.
	)	
		





from Profiles_Employee_Info as employee
where Username = @username and Profile = @profile

FOR
XML PATH('Employee'),Elements, Root('Resumes') -- The element name for each row.

)
exec dbo.writetofile @xml, @filepath

Open in new window

0
Comment
Question by:imstac73
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 33558937

Set @filepath = 'C:\"' + @username + '".xml'

should be:


Set @filepath = 'C:\' + @username + '.xml'
0
 

Author Comment

by:imstac73
ID: 33558987
Awesome, that worked.  Thanks so much!
0

Featured Post

Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

Question has a verified solution.

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

This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

695 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