Home All Groups Group Topic Archive Search About

Export the results from a view to a .csv from the command line

Author
26 Apr 2006 7:48 AM
SecAnalyst
I currently have a view setup in SQL2005 and I need the results from
this view exported to a .csv file. (The view draws information from
four tables within a single DB)

In itself this is easy enough however I need this to be done from the
command line..............

Is this possible & if so how do I go about it ??

Author
26 Apr 2006 2:02 PM
Jasper Smith
You can use sqlcmd or bcp to do this (see BOL for syntax) e.g.

sqlcmd -S (local) -E -s, -Q "set nocount on select * from
Northwind.dbo.[Alphabetical list of products]" -o c:\view.csv -h-1 -W

bcp "select * from Northwind.dbo.[Alphabetical list of products]" queryout
c:\viewbcp.csv -S SQL2005 -T -w

--
HTH,
Jasper Smith (SQL Server MVP)
http://www.sqldbatips.com


Show quote
"SecAnalyst" <SecAnal***@googlemail.com> wrote in message
news:1146037700.594336.310260@u72g2000cwu.googlegroups.com...
>I currently have a view setup in SQL2005 and I need the results from
> this view exported to a .csv file. (The view draws information from
> four tables within a single DB)
>
> In itself this is easy enough however I need this to be done from the
> command line..............
>
> Is this possible & if so how do I go about it ??
>
Author
26 Apr 2006 3:23 PM
Linchi Shea
Hmmm... Will this give you the data in the csv format?

Linchi

Show quote
"Jasper Smith" wrote:

> You can use sqlcmd or bcp to do this (see BOL for syntax) e.g.
>
> sqlcmd -S (local) -E -s, -Q "set nocount on select * from
> Northwind.dbo.[Alphabetical list of products]" -o c:\view.csv -h-1 -W
>
> bcp "select * from Northwind.dbo.[Alphabetical list of products]" queryout
> c:\viewbcp.csv -S SQL2005 -T -w
>
> --
> HTH,
> Jasper Smith (SQL Server MVP)
> http://www.sqldbatips.com
>
>
> "SecAnalyst" <SecAnal***@googlemail.com> wrote in message
> news:1146037700.594336.310260@u72g2000cwu.googlegroups.com...
> >I currently have a view setup in SQL2005 and I need the results from
> > this view exported to a .csv file. (The view draws information from
> > four tables within a single DB)
> >
> > In itself this is easy enough however I need this to be done from the
> > command line..............
> >
> > Is this possible & if so how do I go about it ??
> >
>
>
>
Author
26 Apr 2006 9:03 PM
Jasper Smith
Works for me :-)

--
HTH,
Jasper Smith (SQL Server MVP)
http://www.sqldbatips.com


Show quote
"Linchi Shea" <LinchiS***@discussions.microsoft.com> wrote in message
news:35C215FD-1033-47A2-BD61-19EEBE7C66D0@microsoft.com...
> Hmmm... Will this give you the data in the csv format?
>
> Linchi
>
> "Jasper Smith" wrote:
>
>> You can use sqlcmd or bcp to do this (see BOL for syntax) e.g.
>>
>> sqlcmd -S (local) -E -s, -Q "set nocount on select * from
>> Northwind.dbo.[Alphabetical list of products]" -o c:\view.csv -h-1 -W
>>
>> bcp "select * from Northwind.dbo.[Alphabetical list of products]"
>> queryout
>> c:\viewbcp.csv -S SQL2005 -T -w
>>
>> --
>> HTH,
>> Jasper Smith (SQL Server MVP)
>> http://www.sqldbatips.com
>>
>>
>> "SecAnalyst" <SecAnal***@googlemail.com> wrote in message
>> news:1146037700.594336.310260@u72g2000cwu.googlegroups.com...
>> >I currently have a view setup in SQL2005 and I need the results from
>> > this view exported to a .csv file. (The view draws information from
>> > four tables within a single DB)
>> >
>> > In itself this is easy enough however I need this to be done from the
>> > command line..............
>> >
>> > Is this possible & if so how do I go about it ??
>> >
>>
>>
>>
Author
16 May 2006 8:45 AM
SecAnalyst
Thanks all - this worked a treat.

AddThis Social Bookmark Button