2012年2月23日星期四

bcp a file into text column

Hi,
I have a table with 1 text column.
I need to bcp a .txt file spread over 6/7 lines into this
table.It should get inserted only in one row and not 6/7
rows.I am using sql2000.
Thanks
arOne way to do it would be:
1-. Bulk Insert the text file to a temp table or loading
table.
E.g.
CREATE TABLE TextTable (
Text varchar (8000)
)
bulk insert texttable
from 'Path of your text file'
2-. Use some procedure like the following to concatenate
all the data in one variable:
-- BEGIN SCRIPT --
declare @.text varchar(7000)
declare @.row varchar(7000)
declare cur cursor for
select Text from texttable
where text is not null
set @.text = ''
open cur
fetch next from cur into @.row
while @.@.fetch_status = 0
begin
set @.text = @.text+SUBSTRING(@.row, 1, LEN(@.row)+1)
fetch next from cur into @.row
end
close cur
deallocate cur
print @.text
-- END SCRIPT --
3-. Insert/update the value in @.text into the destiantion
table.
Edgardo Valdez
MCSD, MCDBA, MCSE, MCP+I
http://www.edgardovaldez.us/
>--Original Message--
>Hi,
>I have a table with 1 text column.
>I need to bcp a .txt file spread over 6/7 lines into this
>table.It should get inserted only in one row and not 6/7
>rows.I am using sql2000.
>Thanks
>ar
>.
>|||AR,
Add a unique row delimiter at the end of the text file like. Make sure this
delimiter doesn't exists in your text file. For example you can use a
delimiter like "*|*"
Also make sure that there is no other character exists in the file after the
delimiter, including newline, tab etc.
CREATE TABLE TextTable (
Text varchar (8000)
)
BULK INSERT TextTable
FROM 'C:\text.txt'
WITH
(
FIELDTERMINATOR = '|',
ROWTERMINATOR = '*|*'
)
select * from TextTable
HTH,
Praveen Maddali,
MCSD, MCDBA
"AR" <ambewadkarrakesh@.johndeere.com> wrote in message
news:038601c368e5$85341b90$a301280a@.phx.gbl...
> Hi,
> I have a table with 1 text column.
> I need to bcp a .txt file spread over 6/7 lines into this
> table.It should get inserted only in one row and not 6/7
> rows.I am using sql2000.
> Thanks
> ar

没有评论:

发表评论