Solved

STORE PROCEDURE Output

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get the latest status 8 32
How to search for strings inside db views 4 28
SQL Improvement  ( Speed) 14 28
SQL Server - Set Field Values ito Zero Based on Related Table 4 28
Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

832 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