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

Explain cursor as data base object?

574


What is the difference between substr and charindex in the sql server?

506


difference between Clustered index and non clustered index ?

570


What are the types of indexes?

590


What is the difference between count () and rowcount ()?

520






What is the syntax to execute the sys.dm_db_missing_index_details? : sql server database administration

618


What is data mart? : sql server analysis services, ssas

592


Describe the left outer join & right outer join. : sql server database administration

583


What are the advantages of user-defined functions over stored procedures in sql server?

458


Do you know how to store and query spatial data?

601


Define magic tables in sql server?

566


What are the limitations/drawbacks or ssrs 2008 r2?

86


How do you handle datasets larger than 50 gb?

140


What is hierarchy, what are its types and difference between them? : sql server analysis services, ssas

696


Is sql different from sql server?

511