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
Author
Message
Posted Sunday, November 17, 2013 4:25 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, March 03, 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)
as
begin
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

end

exec extractnewheadings 'softwaremanufacturer,productname,productversion,licensable'


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


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 9:45 PM
Points: 36,013, Visits: 30,300
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."

"Change is inevitable. Change for the better is not." -- 04 August 2013
(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

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

Add to briefcase

Permissions Expand / Collapse