If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Sybase > Read columns from excel into tables ?!

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-03-07, 02:55
mberggren mberggren is offline
Registered User
 
Join Date: Oct 2007
Posts: 29
Question Read columns from excel into tables ?!

Hi,

I have an excel ark. Collumns A1, B1.
A1 is listing articles and B1 is listing prices. This is a long list. products.xls

A1 B1
Article 1 50
Article 2 40
Article 3 30
etc .. etc..

In Adaptive SQL Server i have two tables.
Article (tbl_article)
Price (tbl_price)

These are linked together with an unique ID called
obj_num

I want to read my excel ark into Adaptive SQL Server and sort out article and price into the right table.

Is this possible ?

Regards
Magnus
Reply With Quote
  #2 (permalink)  
Old 10-04-07, 15:37
stuarta stuarta is offline
Registered User
 
Join Date: Mar 2007
Posts: 86
export the excel to a delimted file..
bcp the file into sybase tbl
Reply With Quote
  #3 (permalink)  
Old 10-04-07, 18:14
mberggren mberggren is offline
Registered User
 
Join Date: Oct 2007
Posts: 29
Thx stuarta,

You donīt have any example code to show me. Have read some about the bcp utility but have no idea how it works out with sybase. The procedure from exporting excel sheets to bcp and from bcp to sybase. Or any good toturials ? Pretty newbi here ..

Regards
Magnus
Reply With Quote
  #4 (permalink)  
Old 10-05-07, 02:50
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
Quote:
Originally Posted by mberggren
These are linked together with an unique ID called obj_num
What value should be used for the insert of obj_num? An identity field?
Reply With Quote
  #5 (permalink)  
Old 10-05-07, 04:14
mberggren mberggren is offline
Registered User
 
Join Date: Oct 2007
Posts: 29
The data type for obj_num is integer
Reply With Quote
  #6 (permalink)  
Old 10-05-07, 04:39
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
From excel Save as type Text (Tab delimited)
then e.g.
Code:
C:\tmp>isql -Usa -P -Spd -w333 -Dtempdb
1> create table t1 (c1 int,c2 char(3),c3 varchar(10))
2> go
1> exit
C:\tmp>more t1.txt
c1      c2      c3
2       x       b
3       y       c
4       z       a

C:\tmp>bcp tempdb..t1 in c:\tmp\t1.txt -Usa -P -Spd -c -F2

Starting copy...

3 rows copied.
Clock Time (ms.): total = 1  Avg = 0 (3000.00 rows per sec.)

C:\tmp>isql -Usa -P -Spd -w333 -Dtempdb
1> select * from t1
2> go
 c1          c2  c3
 ----------- --- ----------
           2 x   b
           3 y   c
           4 z   a

(3 rows affected)
1> drop table t1
Reply With Quote
  #7 (permalink)  
Old 10-05-07, 05:34
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
You can read more about bcp in the ASE Utility Guide
Reply With Quote
  #8 (permalink)  
Old 10-05-07, 07:07
mberggren mberggren is offline
Registered User
 
Join Date: Oct 2007
Posts: 29
Thx,

See if I have time in the weekend to check bcp in the ASE Utility Guide.
Itīs a bit hard to get an clue of this, little bit of an rookie in this area.

I think I have some understadning of what you wrote.

In my case I want to split up the table you create in bcp and sort out price to tbl_price and article to tbl_article when you insert in Sybase

So you write the bcp commands in CMD prompt ?

Regards
Magnus
Reply With Quote
  #9 (permalink)  
Old 10-05-07, 09:57
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
Quote:
Originally Posted by mberggren
In my case I want to split up the table you create in bcp and sort out price to tbl_price and article to tbl_article when you insert in Sybase
You will need a format file to specify which columns should be skipped and if you e.g. want to insert column 3 from the text file into table column 2. It might be easier to just copy and paste your data into a new sheet.

Quote:
Originally Posted by mberggren
So you write the bcp commands in CMD prompt ?
Yes bcp is an executable and should be executed like any other OS command

Last edited by pdreyer; 10-05-07 at 10:03.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On