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

Explain magic tables in sql server?

0 Answers  


What is standby servers? Explain types of standby servers.

0 Answers  


What is mssql?

0 Answers  


What is ms sql server triggers?

0 Answers  


How fixed length strings are truncated and padded?

0 Answers  






Explain sql server authentication modes?

0 Answers  


When is the use of update_statistics command?

0 Answers  


How do I shrink an ldf file?

0 Answers  


What is the cartesian product of the table?

0 Answers  


Explain features of analysis services?

0 Answers  


What is surrogate key? : sql server analysis services, ssas

0 Answers  


What is always encrypted?

0 Answers  


Categories