Showing posts with label extremly. Show all posts
Showing posts with label extremly. Show all posts

Wednesday, March 21, 2012

Importing from a text file

I am extremly new to the SQL serve environment and am trying to import data
from a text file to a table. I figured out how to write an import query and
make table query but I can't seem to be able to figure out how to import dat
a
from a plain old text file. The fields in the query should be something
similiar to the fields in the make table query. Any suggestions?
CREATE TABLE REP
(REP_NUM CHAR(2) PRIMARY KEY,
LAST_NAME CHAR(15) NOT NULL,
FIRST_NAME CHAR(15) NOT NULL,
STREET CHAR(15),
CITY CHAR(15),
STATE CHAR(2),
ZIP CHAR(5),
COMMISSION DECIMAL(7,2),
RATE DECIMAL(3,2));Darrin
It is just an example. I hope you will get an idea
CREATE TABLE TmpStList
(
stFName varchar (10) NOT NULL,
stLName varchar (10) NOT NULL,
stEmail varchar (30) NOT NULL
)
go
The data file (hawk.dat):
"Kelly","Reynold","kelly@.reynold.com"
"John","Smith","bill@.smith.com"
"Sara","Parker","sara@.parker.com"
The format file (hawk.bcp):
8.0
4
1 SQLCHAR 0 1 "\"" 0 first_quote ""
2 SQLCHAR 0 10 "\",\"" 1 stFName ""
3 SQLCHAR 0 10 "\",\"" 2 stLName ""
4 SQLCHAR 0 30 "\"\r\n" 3 stEmail ""
bulk insert TmpStList from 'C:\Staging\hawk.dat'
with (formatfile = 'C:\Staging\hawk.bcp')
select * from TmpStList
"Darrin" <Darrin@.discussions.microsoft.com> wrote in message
news:0C357973-085A-4233-B005-8361E0686B69@.microsoft.com...
>I am extremly new to the SQL serve environment and am trying to import data
> from a text file to a table. I figured out how to write an import query
> and
> make table query but I can't seem to be able to figure out how to import
> data
> from a plain old text file. The fields in the query should be something
> similiar to the fields in the make table query. Any suggestions?
> CREATE TABLE REP
> (REP_NUM CHAR(2) PRIMARY KEY,
> LAST_NAME CHAR(15) NOT NULL,
> FIRST_NAME CHAR(15) NOT NULL,
> STREET CHAR(15),
> CITY CHAR(15),
> STATE CHAR(2),
> ZIP CHAR(5),
> COMMISSION DECIMAL(7,2),
> RATE DECIMAL(3,2));