SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 writing to text file from stored procedure
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

bill_
Starting Member

37 Posts

Posted - 09/26/2013 :  10:47:01  Show Profile  Reply with Quote
Want to write from a table variable to a text file from a stored procedure.
Read about xp_cmdshell bcp etc. but worried because it's supposed to be a security problem and needs to be from a permanent database.
Also am getting error "The EXECUTE permission was denied on the object 'xp_cmdshell'..."

1. Is xp_cmdshell a bad idea to use even if I get permissions ?
2. Can a "permanent" table be used in a stored procedure starting out fresh each time with 0 rows rather than use a table variable ?

James K
Flowing Fount of Yak Knowledge

3585 Posts

Posted - 09/26/2013 :  11:04:02  Show Profile  Reply with Quote
You have to enable xp_cmdshell. By default it is turned off. See here for script to turn it on: http://technet.microsoft.com/en-us/library/ms190693.aspx

If you must write from stored procedure to a file, xp_cmdshell is probably the easiest option. You could use CLR stored procedures with external access instead.

You can use a permanent table or table variable to query from for getting your data. That should not make any difference as far as security goes.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 09/28/2013 :  03:51:00  Show Profile  Reply with Quote
You may also use OPENROWSET to do data export to text file


see


http://www.databasejournal.com/scripts/article.php/3587101/Load-TXT-File-using-OPENROWSET-function.htm

Another way to do it to use SSIS /Export import wizard to create a package to do the data export to text file and call it from sql server job. Then in your sp use sp_start_job to launch the job and do data export.




------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000