dbTalk Databases Forums  

bcp Question

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss bcp Question in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
David Franklin
 
Posts: n/a

Default bcp Question - 03-24-2005 , 09:00 AM






Is there a switch that can be used with bcp to include the column names as
part of the resulting file from a queryout command ?

Thanks in advance



Reply With Quote
  #2  
Old   
Alejandro Mesa
 
Posts: n/a

Default RE: bcp Question - 03-24-2005 , 09:33 AM






Use OSQL instead.


AMB

"David Franklin" wrote:

Quote:
Is there a switch that can be used with bcp to include the column names as
part of the resulting file from a queryout command ?

Thanks in advance




Reply With Quote
  #3  
Old   
David Franklin
 
Posts: n/a

Default Re: bcp Question - 03-24-2005 , 02:15 PM



I am playing around with OSQL and I can't get it to work. Here is what I am
doing in bcp :

bcp "select * from database..view" queryout c:\test.csv -c -R -t "," -U
user -P password

I get everything I need except the column names. If you can get me pointed
in the right direction using OSQL, I would greatly appreciate it.

Thanks


"Alejandro Mesa" <AlejandroMesa (AT) discussions (DOT) microsoft.com> wrote

Quote:
Use OSQL instead.


AMB

"David Franklin" wrote:

Is there a switch that can be used with bcp to include the column names
as
part of the resulting file from a queryout command ?

Thanks in advance






Reply With Quote
  #4  
Old   
Alejandro Mesa
 
Posts: n/a

Default Re: bcp Question - 03-24-2005 , 03:05 PM



Example:

osql -S server_name -E -Q "select orderid, orderdate from dbo.orders" -d
northwind -s "," -o "c:\temp\test.txt"


AMB

"David Franklin" wrote:

Quote:
I am playing around with OSQL and I can't get it to work. Here is what I am
doing in bcp :

bcp "select * from database..view" queryout c:\test.csv -c -R -t "," -U
user -P password

I get everything I need except the column names. If you can get me pointed
in the right direction using OSQL, I would greatly appreciate it.

Thanks


"Alejandro Mesa" <AlejandroMesa (AT) discussions (DOT) microsoft.com> wrote in message
news:778E1F30-B336-4F5B-8E96-CB3B48F6E5C2 (AT) microsoft (DOT) com...
Use OSQL instead.


AMB

"David Franklin" wrote:

Is there a switch that can be used with bcp to include the column names
as
part of the resulting file from a queryout command ?

Thanks in advance







Reply With Quote
  #5  
Old   
David Franklin
 
Posts: n/a

Default Re: bcp Question - 03-24-2005 , 03:47 PM



I am so close, I have one more question - The file is being created, but the
results are wrapping over 2 lines. In bcp, each row of results took just
one line. I'm sure it's just a switch, but I can't figure it out...

"Alejandro Mesa" <AlejandroMesa (AT) discussions (DOT) microsoft.com> wrote

Quote:
Example:

osql -S server_name -E -Q "select orderid, orderdate from dbo.orders" -d
northwind -s "," -o "c:\temp\test.txt"


AMB

"David Franklin" wrote:

I am playing around with OSQL and I can't get it to work. Here is what I
am
doing in bcp :

bcp "select * from database..view" queryout c:\test.csv -c -R -t "," -U
user -P password

I get everything I need except the column names. If you can get me
pointed
in the right direction using OSQL, I would greatly appreciate it.

Thanks


"Alejandro Mesa" <AlejandroMesa (AT) discussions (DOT) microsoft.com> wrote in
message
news:778E1F30-B336-4F5B-8E96-CB3B48F6E5C2 (AT) microsoft (DOT) com...
Use OSQL instead.


AMB

"David Franklin" wrote:

Is there a switch that can be used with bcp to include the column
names
as
part of the resulting file from a queryout command ?

Thanks in advance









Reply With Quote
  #6  
Old   
David DBA
 
Posts: n/a

Default Re: bcp Question - 03-24-2005 , 06:38 PM



From books online:
Title: osql Utility

"-w column_width

Allows the user to set the screen width for output. The default is 80
characters. When an output line has reached its maximum screen width, it
is broken into multiple lines.
"

osql is a command line version of Query analyzer so it defaults to
wrapping the output after 80 characters so that you can see it on a
screen.

set the -w switch to 20000 or something else ridicuously large.



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Reply With Quote
  #7  
Old   
peter miller via SQLMonster.com
 
Posts: n/a

Default Re: bcp Question - 03-25-2005 , 10:55 AM




I ran into this problem just last night.

When I used osql the column headers showed, but it was riddled with the
padded spaces as well as the ----- between the headers and the data.

The solution that I found was to create a view on the fly. This view would
be two selects..

create view DataOutput as
select 'column1 header' as column1, 'column2 header' as column2
union all
select column1, column2 from table.

You may have to convert any #s to string values.

The next step would be to bcp the view.

bcp DataOutput out ........

Once I bcp'd the data, I went ahead and dropped the view. Worked like a
champ for me.

Pete

--
Message posted via http://www.sqlmonster.com

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.