Solved

Dynamic filename path in stored procedure

Posted on 2010-08-30
2
236 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
Comment Utility

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

should be:


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

Author Comment

by:imstac73
Comment Utility
Awesome, that worked.  Thanks so much!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now