473,397 Members | 2,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Problem with uploading data SQL

Hello,

I have problem:

My *.txt file is like it:
"
12345612345678123
abcdefabcdefghabc
" etc.

i want upload data into table (for example TEST) i want to sql read this
file and automatically upload to table.(as job for example)
but i have 3 columns and i dont know how to separate this text to 3 diffrent
text columns

1 column | second column | third column
-----------------------------------------
123456 | 12345678 | 123
abcdef | abcdefgh |abc

PLEASE HELP ME, i dont know how to do it.

Robert Kloma


Jul 20 '05 #1
3 1960
Hi Robert,

i'm using the following stored proc (sp) for this. I suggest to use field
separators to make it
easier to separate the columns. This sp can be executed by a job.
The imported file should look like this:

1234;abcd;1212
321123;kdkdkd;121233

In the sp you have to replace CPRave15 with your database name.

Hope it helps.

Michael Zankl
http://www.zankl-it.de
Berlin

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

/*
================================================== ==========================
==
Syno: imports file specified in @UNCPathFileName into a table, specified
in @DBTable
Use ';' as fieldterminator in the imported file
REMARKS:
- User, who runs this SP, has to be a member of SysAdmin
or BulkAdmin
- User must have Insert-Permission on specified Table or
has to be a member of db_owner
TEST:
DECLARE @RC int,
@UNCPathFileName varchar(1024),
@DBTable varchar(128)
SET @UNCPathFileName = '\\Absrv02\Components\Debitoren.csv'
SET @DBTable = 'cprSYSMD_DebImp'
EXEC @RC = cprIMP_File @UNCPathFileName, @DBTable
PRINT @RC

select * from cprsysmd_debimp
--delete from cprSYSMD_DebImp


Author: MZA, http://www.zankl-it.de, 14.01.2003
================================================== ==========================
==
*/
CREATE PROCEDURE cprIMP_File @UNCPathFileName varchar(1024),
@DBTable varchar(128)
AS
DECLARE @RetVal int,
@Cmd varchar(8000)


--Example
-- BULK INSERT CPRave15.dbo.cprSYSMD_DebImp
-- FROM '\\Absrv02\Components\Debitoren.csv'

SET @Cmd = '
BULK INSERT CPRave15.dbo.' + @DBTable + '
FROM ''' + @UNCPathFileName + '''
WITH (FIELDTERMINATOR = '';'')' --<== IMPORTANT: use a fieldterminator in
imported file

--print @Cmd
EXEC (@Cmd)

SET @RetVal = @@ROWCOUNT

RETURN @RetVal

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

"Robert K" <rk****@hotmail.com> schrieb im Newsbeitrag
news:bi**********@news.onet.pl...
Hello,

I have problem:

My *.txt file is like it:
"
12345612345678123
abcdefabcdefghabc
" etc.

i want upload data into table (for example TEST) i want to sql read this
file and automatically upload to table.(as job for example)
but i have 3 columns and i dont know how to separate this text to 3 diffrent text columns

1 column | second column | third column
-----------------------------------------
123456 | 12345678 | 123
abcdef | abcdefgh |abc

PLEASE HELP ME, i dont know how to do it.

Robert Kloma


Jul 20 '05 #2
"Robert K" <rk****@hotmail.com> wrote in message news:<bi**********@news.onet.pl>...
Hello,

I have problem:

My *.txt file is like it:
"
12345612345678123
abcdefabcdefghabc
" etc.

i want upload data into table (for example TEST) i want to sql read this
file and automatically upload to table.(as job for example)
but i have 3 columns and i dont know how to separate this text to 3 diffrent
text columns

1 column | second column | third column
-----------------------------------------
123456 | 12345678 | 123
abcdef | abcdefgh |abc

PLEASE HELP ME, i dont know how to do it.

Robert Kloma


One option is to create a staging table with one column, load the data
into that table without changing it, then insert into the final table
like this:

insert into dbo.TEST (col1, col2, col3)
select left(StagingColumn, 6), left(StagingColumn, 8),
left(StagingColumn, 3)
from dbo.StagingTable

Simon
Jul 20 '05 #3
hello, thank you for hint but:

i want to read this data
My *.txt file is like it:
"
1234567890

" etc

1 column | second column | third column
-----------------------------------------
12 | 3456 | 789

how to do it ,
One option is to create a staging table with one column, load the data
into that table without changing it, then insert into the final table
like this:

insert into dbo.TEST (col1, col2, col3)
select left(StagingColumn, 2), left(StagingColumn, 4),
left(StagingColumn, 4)
from dbo.StagingTable


the result is of this is
1 column | second column | third column
-----------------------------------------
12 | 1234 | 1234

Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mike | last post by:
Hi i have a problem in asp.ne i am uploading file to the server using htmlinput controls and every thing is o but i try to upload larger file to the server like more than 4 mb and about 10mb i got...
4
by: R Reyes | last post by:
I am trying to code a file uploader (for forum/email attachments) from the client computer to a remote web server via the PUT method (since POST is not allowed ). However, the upload works ONLY...
13
by: Sky Sigal | last post by:
I have created an IHttpHandler that waits for uploads as attachments for a webmail interface, and saves it to a directory that is defined in config.xml. My question is the following: assuming...
4
by: Himanshu | last post by:
hi, Can anybody tell me that thru asp.net using c#, how can we upload and download physical files in any table of SQL Server Database. the uploading part is running successfully but the...
3
by: Carlos | last post by:
Hello Forum, I would appreciate it if you could recommend settings to use auto-vacuum in my version 7.4 database. I am uploading several thousands records in the database at a rate of ~1 second...
0
by: Ramakrishnan Nagarajan | last post by:
Hi, I am facing a problem in uploading Excel data to the Database. While uploading my code reads Excel Data using OleDbReader and store into a dataset by looping through the OleDbReader result...
2
by: prakharv | last post by:
Hi All, Below is the code which I am using to upload a jpeg file to the server. But the problem I am facing is that it is not copying the entire contents of the image file to the webserver and it...
15
by: =?ISO-8859-1?Q?J=F8rn?= Dahl-Stamnes | last post by:
Hello folks, I need some help/advice FAST. I have problems with addslashes on my web-servers. After uploading a file, I read the uploaded file, use addslashes on the read data and then insert...
7
by: jambroo | last post by:
Hello, We are currently having issues uploading files using PHP. It seems files below 8MB are uploaded fine, however files above 8.2MB cause the page to timeout or show a 'Cannot find server or...
3
ganesanji
by: ganesanji | last post by:
hi all, I have written a php coding for uploading a file to a specific folder or location in server which is a Linux server. I think the coding for file uploaing is correct. But it does not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.