Click here to monitor SSC
SQLServerCentral is supported by Redgate
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: Today @ 8:40 AM
Points: 42,081, Visits: 39,472
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."

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

Add to briefcase

Permissions Expand / Collapse