Solved

Dynamic filename path in stored procedure

Posted on 2010-08-30
2
238 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
2 Comments
 
LVL 142

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

831 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