Solved

STORE PROCEDURE Output

Posted on 2002-07-24
3
651 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to shrink a transaction log file down to a reasonable size.

615 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