.103.1.102!news2.chicago.cic.net!iagnet.net!128.223.220.30!logbridge.uoregon.edu!enews.sgi.com!news.corp.sgi.com!mew.corp.sgi.com!pablo
Subject: Sybase FAQ: 6/16 - section 5
Date: 1 Sep 1997 06:02:21 GMT
Summary: Info about SQL Server, bcp, isql and other goodies
Posting-Frequency: monthly

Archive-name: databases/sybase-faq/part6
URL: http://reality.sgi.com/pablo/Sybase_FAQ

                        Q5.1: HOW DO I BCP NULL DATES?
                                       
   
     _________________________________________________________________
   
   As long as there is _nothing_ between the field delimiters in your
   data, a null will be entered. If there's a space, the value will be
   Jan 1, 1900.
   
   You can use _sed(1)_ to squeeze blanks out of fields:
   

 sed -e 's/|[ ]*|/||/g' old_file > new_file

   
     _________________________________________________________________

          Q5.2: CAN I USE A NAMED PIPE TO _BCP/DUMP_ DATA OUT OR IN?
                                       
   _System 10 and above._
     _________________________________________________________________
   
   If you would like to _bcp_ copy from one table to a named pipe and
   compress:
    1. %mknod bcp.pipe p
    2. %compress sysobjects.Z &
    3. %bcp master..sysobjects out bcp.pipe -c -U .. > bcp.pipe
    4. Use _ps(1)_ to determine when the _compress_ finishes.
       
   To bcp _from_ my1db..dummy_table_1 _to_ my2db..dummy_table_2:
    1. %mknod bcp.pipe p
    2. %bcp my2db..dummy_table_2 in bcp.pipe -c -U .. &
       
     To avoid confusion between the above _bcp_ and the next, you may
     choose to either use a separate window or redirect the output to a
     file.
    3. %bcp my1db..dummy_table_1 out bcp.pipe -c -U ..
       
   
     _________________________________________________________________

                       Q5.3: HOW DO I EXCLUDE A COLUMN?
                                       
   
     _________________________________________________________________
   
   The documentation _Utility programs for Unix_ describes the use of
   format files, including the field _Server Column Order._ _Server
   Column Order_ must equal the _colid_ of the column, or 0 if the host
   file field will not be loaded into any table column.
   
   I don't know if anyone has got this feature to work. So, here is
   another way of _removing_ the column. In your example, you want to
   remove the last column. I am going to include another example to
   remove the second column and include a fourth column. Why? Because it
   is harder. First example will deal with _removing_ the last column.
   
  Removing the Last Column
  
   Edit your _bcpout.fmt_ file and look for the changes I made below.
   Using the following bcpout.fmt file to dump the data:
   

--- bcpout.fmt
10.0
2 <------------------ Changed number of columns to BCP to two
1   SYBINT4 0  4       "<**>"  1   counter
2   SYBCHAR 1  512     "\n"    2   text1 <--- Replace <**> with \n
3   SYBCHAR 1  512     "\n"    3   text2 <--- DELETE THIS LINE

   Now recreate the table with the last column removed and use the same
   _bcpout.fmt_ file to BCP back in the data.
   
   Now let's try removing the second column out four columns on a table.
   
  Removing the Second out of Four Columns
  
   Edit the _bcpout.fmt_ file and look for the changes I made below.
   Using the following _bcpout.fmt_ file to dump the data:
   

--- bcpout.fmt
10.0
3 <------------------ Changed number of columns to BCP to three
1   SYBINT4 0  4       "<**>"  1   counter
2   SYBCHAR 1  512     "<**>"  2   text1 <--- DELETE THIS LINE
2   SYBCHAR 1  512     "<**>"  3   text2 <--- Change number items to 2
3   SYBCHAR 1  512     "\n"    4   text3 <--- Change number items to 3
---

  Including the Fourth Column
  
   Now copy the _bcpout.fmt_ to _bcpin.fmt_, recreate table with col 2
   removed, and edit _bcpin.fmt_ file:
   

--- bcpin.fmt
10.0
3
1   SYBINT4 0  4       "<**>"  1   counter
2   SYBCHAR 1  512     "<**>"  2   text2 <-- Change column id to 2
3   SYBCHAR 1  512     "\n"    3   text3 <-- Change column id to 3
---

   
     _________________________________________________________________
-- 
Pablo Sanchez              | Ph # (415) 933.3812        Fax # (415) 933.2821
pablo@sgi.com              | Pg # (800) 930.5635  -or-  pablo_p@pager.sgi.com
===============================================================================
I am accountable for my actions.   http://reality.sgi.com/pablo [ /Sybase_FAQ ]
