Solved

How to make a txt file export from this UDF?

Posted on 2006-06-22
6
272 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

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.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how the fundamental information of how to create a table.

758 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

22 Experts available now in Live!

Get 1:1 Help Now