Solved

STORE PROCEDURE Output

Posted on 2002-07-24
3
649 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

679 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