473,395 Members | 1,584 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,395 software developers and data experts.

SQL to Text file

hi.
please guide me how to get the output of a PROCEDURE into a TEXT-FILE placed anywhere in hard-disc.
i am using SQL server 2000.
Sep 17 '07 #1
8 12429
basically i have to keep the track of errors encountered in a procdure, similar to a log file. it should display successful if the execution succeeds and failure plus some additional info regarding the record if execution fails
Sep 17 '07 #2
azimmer
200 Expert 100+
One option is to log to a table and then bcp it to a file when you're done. On bcp see: http://msdn2.microsoft.com/en-us/library/ms162802.aspx (I believe bcp is available for SQL Server 2000 as well but I'm not positive.)

Another option is to use the OPENDATASOURCE functionality with a text file output. I've never tried this but see no reason why it shouldn't work.

A third one is to use DTS packages (DTS can output to text file).
Sep 17 '07 #3
thanks a lot.... but using tables( for bcp) is something which is not cost efficient.
and the error logging through DTS is providing me the reason for error but not the record for which error was raised. i want the description corresponding to each recordset, whatever be the result, failure or success.

i will try for OPENDATASOURCE. in the meantime any other suggestions?


One option is to log to a table and then bcp it to a file when you're done. On bcp see: http://msdn2.microsoft.com/en-us/library/ms162802.aspx (I believe bcp is available for SQL Server 2000 as well but I'm not positive.)

Another option is to use the OPENDATASOURCE functionality with a text file output. I've never tried this but see no reason why it shouldn't work.

A third one is to use DTS packages (DTS can output to text file).
Sep 18 '07 #4
OPENDATASOURCE is not getting me anywhere...
cant figure out how could i write anything into a textfile using SQL

thanks a lot.... but using tables( for bcp) is something which is not cost efficient.
and the error logging through DTS is providing me the reason for error but not the record for which error was raised. i want the description corresponding to each recordset, whatever be the result, failure or success.

i will try for OPENDATASOURCE. in the meantime any other suggestions?
Sep 18 '07 #5
azimmer
200 Expert 100+
OPENDATASOURCE is not getting me anywhere...
cant figure out how could i write anything into a textfile using SQL
Try this, it works:
Expand|Select|Wrap|Line Numbers
  1. INSERT OPENROWSET('Microsoft.Jet.OLEDB.4.0',
  2. 'Text;Database=d:\Temp',new#txt)
  3. SELECT myField
  4. FROM myTable
  5.  
Important: d:\Temp\new.txt must exist before executing this statement and has to have a myField field header.

I hope it gets you somewhere. I'm no expert on this, sorry.
Sep 18 '07 #6
[quote=azimmer]Try this, it works:
Expand|Select|Wrap|Line Numbers
  1. INSERT OPENROWSET('Microsoft.Jet.OLEDB.4.0',
  2. 'Text;Database=d:\Temp',new#txt)
  3. SELECT myField
  4. FROM myTable
  5.  
thanks. but in my case i have to get the result from procdure and not from any table present in database.
Sep 19 '07 #7
azimmer
200 Expert 100+
[quote=KritiGuleria]
Try this, it works:
Expand|Select|Wrap|Line Numbers
  1. INSERT OPENROWSET('Microsoft.Jet.OLEDB.4.0',
  2. 'Text;Database=d:\Temp',new#txt)
  3. SELECT myField
  4. FROM myTable
  5.  
thanks. but in my case i have to get the result from procdure and not from any table present in database.
INSERT works with fixed values (or variables) as well:
Expand|Select|Wrap|Line Numbers
  1. INSERT OPENROWSET('Microsoft.Jet.OLEDB.4.0',
  2. 'Text;Database=d:\Temp',new#txt)
  3. VALUES ('Error code=12','Record no=1111')
  4.  
I used SELECT as an example only. It is the same INSERT as for tables, only the "table" is an OPENROWSET.
Sep 19 '07 #8
[quote=azimmer][quote=KritiGuleria]
INSERT works with fixed values (or variables) as well:

hey, thanks a lot!!
Sep 21 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

22
by: Ling Lee | last post by:
Hi all. I'm trying to write a program that: 1) Ask me what file I want to count number of lines in, and then counts the lines and writes the answear out. 2) I made the first part like this: ...
1
by: Rigga | last post by:
Hi, I am new to Python and need to parse a text file and cut parts out i.e. say the text file contained 5 rows of text: line 1 of the text file line 2 of the text file line 3 of the text...
27
by: Eric | last post by:
Assume that disk space is not an issue (the files will be small < 5k in general for the purpose of storing preferences) Assume that transportation to another OS may never occur. Are there...
16
by: thenightfly | last post by:
Ok, I know all about how binary numbers translate into text characters. My question is what exactly IS a text character? Is it a bitmap?
7
by: Chris | last post by:
Hi I can use a text file as a datasource but am unable to get the datatable to see the text file as having multiple columns. Everything gets put into the first column in the datatable. Sample of...
3
by: bbepristis | last post by:
Hey all I have this code that reads from one text file writes to another unless im on a certian line then it writes the new data however it only seems to do about 40 lines then quits and I cant...
1
by: Osoccer | last post by:
...to a different folder and in the relocated file concatenates all of the lines in one long string with a space between each line element. Here is a fuller statement of the problem: I need a...
10
by: bluemountain | last post by:
Hi there, Iam new to python forms and programming too I had a text file where i need to extract few words of data from the header(which is of 3 lines) and search for the keyword TEXT1, TEXT2,...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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.