Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 copy from file into a table

Author  Topic 

zukipower
Starting Member

10 Posts

Posted - 2010-05-12 : 09:41:16
I have a problem regarding importing of data from a file into a table in the sql database.

The textfile i want to import would look like this:
old spare part number;replacement code;new spare part number
10621631;1;20398389
01062165;1;20398014
01062167;1;20383514
01062172;1;03093911

I've found a script as follows:
COPY [ BINARY ]tbl_spr_replacement[ WITH OIDS ]
FROM { 'c:\fil.txt' | stdin }
[ [USING] DELIMITERS ';' ]
[ WITH NULL AS 'null_string' ]

it gets an error on the [ BINARY ], and im not sure if this is right syntax at all, or that SQL supports this.

Do any of you have a clue on how i can import a file into a table?

I really want to learn this language, so if any of you have any good tutorial links or link to a very good SQL book i could buy i would very much appreciate it. :)

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-05-12 : 09:49:23
Don't know the posted syntax. Is it MS SQL Server???

See here for example:
http://blog.sqlauthority.com/2008/02/06/sql-server-import-csv-file-into-sql-server-using-bulk-insert-load-comma-delimited-file-into-sql-server/


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

zukipower
Starting Member

10 Posts

Posted - 2010-05-12 : 10:29:49
I'm not sure if that was MS SQL, but since it said it was wrong syntax i guess it is something else.

Thank you very much for the link. It worked perfectly! :)
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-05-12 : 10:31:11
welcome


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -