Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

STORE PROCEDURE Output

Posted on 2002-07-24
3
Medium Priority
?
652 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 200 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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

688 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