?
Solved

Dynamic filename path in stored procedure

Posted on 2010-08-30
2
Medium Priority
?
242 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 2000 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

765 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