Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase

Write to text file Expand / Collapse
Posted Sunday, November 17, 2013 4:25 PM


Group: General Forum Members
Last Login: Monday, March 3, 2014 4:58 PM
Points: 130, Visits: 214
Hi Professionals

I am trying to write a variable with column headings to a text file but it does not seem to be working and I am not sure where I am going wrong.

It creates a file called file.txtsoftwaremanufacturer and inside the file is the rest of the parameter 'productname','productversion','licensable'

here is my code

alter procedure [dbo].[extractnewheadings]
@importedquery nvarchar(1000)
Declare @sCmd varchar(256)
--set @importedquery = REPLACE(@importedquery,',', ''',''' );
--print @importedquery
SET @sCmd = 'echo > C:\inetpub\wwwroot\cleansed\file.txt' + @importedquery + ''
exec master..xp_cmdshell @sCmd, no_output


exec extractnewheadings 'softwaremanufacturer,productname,productversion,licensable'

Post #1515035
Posted Sunday, November 17, 2013 9:55 PM



Group: General Forum Members
Last Login: Yesterday @ 8:50 PM
Points: 38,552, Visits: 35,555
Try this for your command...

SET @sCmd = 'echo ' + @importedquery + ' > "C:\inetpub\wwwroot\cleansed\file.txt"'

Also, you should check any such concatenated variables for "DOS Injection" just like you would for "SQL Injection".

--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Favorite Quotes:
"Has anyone ever told you that a query you have written runs too fast?" - Dwain Camps - 6 Mar 2014

Helpful Links:
How to post code problems
How to post performance problems
Post #1515061
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse