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 > Data Access, Manipulation & Batch Languages > ANSI SQL > Reading a text file from a stored procedure.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-12-04, 09:42
BrutusBuckeye BrutusBuckeye is offline
Registered User
 
Join Date: Nov 2002
Posts: 13
Reading a text file from a stored procedure.

A rookie question - all I want to do is open a text file x.txt and read each line - no bcp or bulk insert required.

Is there a simple way to do this ?

Thanks in advance to all who reply !
Reply With Quote
  #2 (permalink)  
Old 04-12-04, 12:53
rdjabarov rdjabarov is offline
Registered User
 
Join Date: Jul 2003
Location: San Antonio, TX
Posts: 3,611
Not with ANSI-92 syntax. You'd have to use specific DBMS extensions for it. Pick the engine (Oracle, SQL Server, UDB, etc.) and post accordingly.
Reply With Quote
  #3 (permalink)  
Old 04-12-04, 12:57
BrutusBuckeye BrutusBuckeye is offline
Registered User
 
Join Date: Nov 2002
Posts: 13
I am using SQL Server 7.0.

I know how to do this in Oracle using the DBMS functions. Are there similar functions in MSSQL ?

Thanks for your reply !
Reply With Quote
  #4 (permalink)  
Old 04-12-04, 13:01
rdjabarov rdjabarov is offline
Registered User
 
Join Date: Jul 2003
Location: San Antonio, TX
Posts: 3,611
I use sp_OAxxx with FileSystemObject.
Reply With Quote
  #5 (permalink)  
Old 04-12-04, 13:12
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
Quote:
Originally posted by BrutusBuckeye
I am using SQL Server 7.0.

I know how to do this in Oracle using the DBMS functions. Are there similar functions in MSSQL ?

Thanks for your reply !
In my opinion, this is one of the fundamental design flaws in Oracle. They are attempting to make PL/SQL a programming language instead of a data[base] manipulation language.

If you stop and think about it, reading text the way that you want to do it is a client side activity. Using BCP or BULK INSERT are server side activities. There is a fundamental difference between them (which machine the code actually runs on)!

Any solution you find for MS-SQL will involve server side activity. Sybase (now Microsoft) never intended for Transact-SQL scripts to run on the client, they always assumed that those Transact-SQL scripts would run on the server. That is exactly why user interface code, file access, etc are absent from Transact-SQL... The absence is by design.

Using Microsoft Transact-SQL, you'll need to either adopt a server centric point of view, or write your client side code using the client language. There is a clear distinction between the client and server in Transact-SQL.

-PatP
Reply With Quote
  #6 (permalink)  
Old 04-12-04, 13:29
rdjabarov rdjabarov is offline
Registered User
 
Join Date: Jul 2003
Location: San Antonio, TX
Posts: 3,611
BrutusBuckeye, Pat has a very strong opinion about all this

I'd still use sp_OAxxx if you insist on reading a text file one line at a time, but why bother? Use BULK INSERT and then deal with it in a recordset-based fashion!
Reply With Quote
  #7 (permalink)  
Old 04-12-04, 13:33
BrutusBuckeye BrutusBuckeye is offline
Registered User
 
Join Date: Nov 2002
Posts: 13
UNCLE !!!!

Thanks for all your help. I am indeed going the Bulk Insert route.

Thanks again from the school of hard knocks..
Reply With Quote
  #8 (permalink)  
Old 04-12-04, 13:41
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
Quote:
Originally posted by rdjabarov
BrutusBuckeye, Pat has a very strong opinion about all this
Dang! Did I let that secret out again ?!?!

-PatP
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