Solved

STORE PROCEDURE Output

Posted on 2002-07-24
3
644 Views
Last Modified: 2011-10-03
Hello,

I'd like know how can we create an output file to receive the result of one STORE PROCEDURE like that

CREATE PROCEDURE myproc
@test int OUTPUT
AS
SELECT * FROM Journal

RETURN 0
GO

That means the data from the query SELECT * FROM Journal
has been to created in one file.
Thank you.
0
Comment
Question by:amara_78456
3 Comments
 
LVL 9

Accepted Solution

by:
miron earned 50 total points
ID: 7176241
try this method. Its major advantage is that you need not to use xp_cmdshell procedure, this stored procedure is so powerful that it basically puts entire SQL Server security to nil.

create directory C:\flatfile on the local machine to SQL Server
under directory C:\flatfile create 2 text files

output.txt - should be empty
schema.ini - should contain

[output.txt]
ColNameHeader=False
MaxScanRows=0
Format=TabDelimited
Col1=column_name DATA_TYPE <width_for_textual_data>
Col2=column_name DATA_TYPE <width_for_textual_data>
Col3=column_name DATA_TYPE <width_for_textual_data>
...
Coln=column_name DATA_TYPE <width_for_textual_data>

Where DATA_TYPE is mapped accordingly

SQL Server
int
schema.ini
Long

SQL Server
smallint
schema.ini
Short

SQL Server
tinyint
schema.ini
Byte

SQL Server
boolean
schema.ini
Long

SQL Server
decimal | numeric | real
schema.ini
Double

SQL Server
datetime
schema.ini
Datetime

SQL Server
image
schema.ini
OLE

SQL Server
binary | text | ntext
schema.ini
Memo

SQL Server
char | nchar | varchar | nvarchar
schema.ini
Text

the text data type need to be augmented with the width attribute
for example, if SQL Server type is varchar(35)
then column data type in schema.ini need to be defined as
Col<Ordinal>=<COLUMN_NAME> Text 35

execute sp_addlinkedserver
               @server   = 'txtsrv'
               , @srvproduct = 'Jet 4.0'
               , @provider = 'Microsoft.Jet.OLEDB.4.0'
               , @datasrc   = 'C:\flatfile'
               , @location = NULL
               , @provstr = 'Text'
GO
EXEC sp_addlinkedsrvlogin 'txtsrv'   , FALSE , 'sa', 'Admin' , NULL
GO

CREATE VIEW output_file
AS
     select
     <column_list>
     from
     txtsrv...[outpu#txt]
GO

insert into output_file
(
     <column_list>
)
select
     <column_list>
from <source_table>

-- Cheers
0
 

Expert Comment

by:CleanupPing
ID: 9280057
amara_78456:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now