From: David C on
Is there a way in TSQL that I can output the results of a view to a
delimited text file? Thanks.

David


From: Erland Sommarskog on
David C (dlchase(a)lifetimeinc.com) writes:
> Is there a way in TSQL that I can output the results of a view to a
> delimited text file? Thanks.

There is no built-in command for that.

What you can do is invoke BCP through xp_cmdshell, but your DBA may not
agree to enable xp_cmdshell, as it is considered a security risk.

It would be better to do this from a client program.

If you want to do this from an Agent job, you could enter the job as a
CmdExec job that runs BCP. Obviously SSIS/DTS can be an alternative - if
you have knowledge in them. (Personally, I don't.)


--
Erland Sommarskog, SQL Server MVP, esquel(a)sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
From: David C on

"Erland Sommarskog" <esquel(a)sommarskog.se> wrote in message
news:Xns9CD6974625316Yazorman(a)127.0.0.1...
> David C (dlchase(a)lifetimeinc.com) writes:
>> Is there a way in TSQL that I can output the results of a view to a
>> delimited text file? Thanks.
>
> There is no built-in command for that.
>
> What you can do is invoke BCP through xp_cmdshell, but your DBA may not
> agree to enable xp_cmdshell, as it is considered a security risk.
>
> It would be better to do this from a client program.
>
> If you want to do this from an Agent job, you could enter the job as a
> CmdExec job that runs BCP. Obviously SSIS/DTS can be an alternative - if
> you have knowledge in them. (Personally, I don't.)
>
>
> --
> Erland Sommarskog, SQL Server MVP, esquel(a)sommarskog.se
>
> Books Online for SQL Server 2005 at
> http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
> Books Online for SQL Server 2000 at
> http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

The database is used in an ASP.Net web application. Does that help?
Thanks.

David


From: Russell Fields on
David,

You can use BCP to select out a view to a text file. There are formatting
options, but the simplest would be:

BCP database.schema.viewname OUT mytextfile.txt -c -S Servername -T

You could call this from within TSQL by using the xp_cmdshell stored
procedure, or you could launch this as a SQL Agent job step.

RLF


"David C" wrote:

> Is there a way in TSQL that I can output the results of a view to a
> delimited text file? Thanks.
>
> David
>
>
> .
>
From: Plamen Ratchev on
If the data set returned by the view is not very large, then you can return it as data set in ASP.NET and use the .NET
functions to format and save to text file. Here is example on saving to file:
http://www.4guysfromrolla.com/articles/072303-1.aspx

--
Plamen Ratchev
http://www.SQLStudio.com