?
Solved

How to make a txt file export from this UDF?

Posted on 2006-06-22
6
Medium Priority
?
293 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
Independent Software Vendors: 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!

 

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 200 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Suggested Courses

864 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