Solved

How to make a txt file export from this UDF?

Posted on 2006-06-22
6
279 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
[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
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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
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
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 video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

726 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