Solved

How to make a txt file export from this UDF?

Posted on 2006-06-22
6
276 Views
Last Modified: 2012-08-13
Hi experts,

I have a UDF be created, now I want to export the returned table to txt type file to my C:\data, how can I do it? thanks.

/**** Create UDF****/
CREATE  FUNCTION LargeOrder ( @Quantity int )
RETURNS @OrderShipperTab TABLE
   (
    INVOICE_ID     int,
    PRODUCT_ID   nvarchar(10),
    QUANTITY       int,
    TOTAL_PRICE   int,
    ACCOUNT_ID   varchar (12)
   )
AS
BEGIN
   INSERT @OrderShipperTab
        SELECT C.INVOICE_ID, C.PRODUCT_ID,
               C.QUANTITY, C.TOTAL_PRICE,C.ACCOUNT_ID
        FROM CA_PURCHASES C
        WHERE C.QUANTITY > @Quantity
   RETURN
END
GO

/***** the table returned by the function**/
SELECT * FROM LARGEORDER (500)
GO
0
Comment
Question by:LIULIHUA
6 Comments
 
LVL 10

Expert Comment

by:pai_prasad
ID: 16962322
try bcp...
from command prompt
0
 

Author Comment

by:LIULIHUA
ID: 16962346
i am new, would you please list the code step by step, much thanks.
0
 
LVL 21

Expert Comment

by:mastoo
ID: 16962657
If this is a one-time thing and you want a csv, you can just use query analyzer.  Set the query results to be in a grid, do your select, right click the upper left box in the grid and select "save as"
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

Author Comment

by:LIULIHUA
ID: 16962710
No, this gona to be set up in DTS Execut SQL task to run automatically when the scheduel due.
I just found a code from this site as following, but it gave me message as below.
/**** BCP*****/
EXEC master..xp_cmdshell 'bcp ""SELECT  *  FROM Largeorder (500) "" queryout ""c:\data\export.csv"" -U uname -P password -c -t,'

/**** out put****/
Copy direction must be either 'in', 'out' or 'format'.
usage: bcp {dbtable | query} {in | out | queryout | format} datafile
  [-m maxerrors]            [-f formatfile]          [-e errfile]
  [-F firstrow]             [-L lastrow]             [-b batchsize]
  [-n native type]          [-c character type]      [-w wide character type]
  [-N keep non-text native] [-V file format version] [-q quoted identifier]
  [-C code page specifier]  [-t field terminator]    [-r row terminator]
  [-i inputfile]            [-o outfile]             [-a packetsize]
  [-S server name]          [-U username]            [-P password]
  [-T trusted connection]   [-v version]             [-R regional enable]
  [-k keep null values]     [-E keep identity values]
  [-h "load hints"]
NULL
0
 
LVL 20

Accepted Solution

by:
Sirees earned 50 total points
ID: 16962795
<<No, this gona to be set up in DTS Execut SQL task to run automatically when the scheduel due. >>

In DTS you have an option to choose destination text file and useTransform data task between connection and text file.
0
 

Author Comment

by:LIULIHUA
ID: 16963734
It works, thanks.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
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…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

932 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

14 Experts available now in Live!

Get 1:1 Help Now