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?



Is it possible to create a stored procedure that runs a query and outputs the results to a text fi..

Answer / 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

More SQL Server Interview Questions

What are indexers?

0 Answers  


What are the basic functions for master, msdb, model, tempdb and resource databases?

0 Answers  


How to connect php with different port numbers?

0 Answers  


user defined datatypes

1 Answers   Wipro,


What is data integrity? Explain constraints?

1 Answers   Thinksoft,


What are the different types of sub-queries?

0 Answers  


Can you insert NULL in unique column?

0 Answers   MCN Solutions,


Explain different types of lock modes in sql server 2000?

0 Answers  


How to get @@error and @@rowcount at the same time?

0 Answers  


What do you mean by recursive stored procedure?

0 Answers  


How do you fine the performance tunning?

2 Answers   Accenture,


What are the new features in SQL Server 2005?

3 Answers   Emphasis,


Categories