Is it possible to create a stored procedure that runs a
query and outputs the results to a text file and allows me
to add extra delimeters and static field info. If so How?

Answer Posted / guest

SQL Server has no native command for outputting query
results to a file. You can use the extended
stored procedure xp_cmdshell and call isql (command-line
SQL) with your query and output the results to a file. Any
delimiters would need to be part of the SELECT string:

DECLARE @isqlString varchar(255)

SELECT @isqlString = 'isql -Q "SELECT DateCol FROM
NorthwindTest.dbo.Test" -E -o C:\Results.txt'

EXEC master..xp_cmdshell @isqlString

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between local and global temporary tables?

592


what exactly sql injuction.how to overcome.....

2043


How many columns can exist together per table?

710


How do I get to sql server configuration manager?

522


How can you find out which stored procedures are recompiling?

516






Write a program to fetch first 10 records from a file?

607


How to rebuild all indexes on a single table?

592


What do you mean by an execution plan? Why is it used? How would you view it?

534


Help!!!!!!!!!!!! My database has gone offline, it is highlighted as 'Suspect'. Foolishly, i haven't got a recent back up. Is there a way of quickly restoring the database? Thank you

1305


How can I change procedure name in sql server?

541


What is sql server replication? : sql server replication

540


What is command parameter in ssrs?

120


What is the difference between NOROW and LOCKROW?

2244


Why use “in” clause in sql server?

560


How are the unique and primary key constraints different?

571