• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1411
  • Last Modified:

importing data from a csv file into a sybase table

Can any one give me the import statement to import data from a csv file into a sybase table ?
0
Joserip
Asked:
Joserip
  • 4
  • 2
1 Solution
 
Joe WoodhousePrincipal ConsultantCommented:
Assuming carriage returns for the row delimiters:

bcp [database].[owner].[table] in [file] -U[user] -S[server] -c -t,

You could optionally add " -e [errorfile] " to produce a file where any failed rows will be logged.

You may have to enable the database option "select into" in the destination database depending on whether this table has indexes or triggers. (Enable if they do - this will be "fast bcp".)

The Utility Guide for Sybase has a good chapter on using bcp.

Joe
0
 
JoseripAuthor Commented:
Thanks ! if my .csv file is in C drive how will I give this comand
0
 
Joe WoodhousePrincipal ConsultantCommented:
The Sybase client must have been installed. You can run this from a DOS prompt or command line. You must supply the full path to the file, or be in its local directory.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
JoseripAuthor Commented:
Thanks ! I am running it through a query tool conntecting to the DB . I am able to select the records in the table etc .

If I run the select commnad this way it runs well select count(*) from tablename

so I am using the bcp command this way

bcp tablename  in 'c:\test.csv'  -U user1  -S servername  -c -t

but I am getting an error near the 'in'  area
0
 
Joe WoodhousePrincipal ConsultantCommented:
Ah, I see a couple of problems in your command line.

#1: bcp must specify, at a minimum, the database you're loading into.
#2: You must put the comma after the "-t"... "-t" means "use this character for your column terminators", and you want to use a comma.

Your actual command line would be, including the final comma:

bcp  databasename..tablename  in  "c:\test.csv"  -Uuser  -Sserver  -c  -t,

Note the two dots between the database and table names. This is standard Sybase syntax, it is short for

database.owner.object

If the owner is the default "dbo" (database owner) then you can omit it, but you still need the dots on either side of it.

Let us know how that goes!
0
 
Joe WoodhousePrincipal ConsultantCommented:
Hi, how did you go with that?
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now