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 is difference between equi join and inner join?

1 Answers  


What are the types of containers in ssis?

1 Answers  


What is dirty read?

1 Answers  


Explain what are the different index configurations a table can have?

1 Answers  


Please explain that what are the basic functions for master, msdb, model, tempdb and resource databases? : SQL Server Architecture

1 Answers  


What do you mean by subquery?

1 Answers  


What are the restraints imposed on the table design by a merge replication?

1 Answers  


can i write function in stored procedure and stored procedure in function and nested procedure.Give one example for each question?

1 Answers   Cap Gemini, TCS,


Explain indexed view?

1 Answers  


What does it mean if @@cursor_row returns a negative number?

1 Answers  


Does order by actually change the order of the data in the tables or does it just change the output?

1 Answers  


Explain difference between cross join and full outer join?

1 Answers  


Categories