Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Export data from MS-SQL 8.0 to text without using bcp or xp_cmdshell

Posted on 2004-08-30
4
Medium Priority
?
242 Views
Last Modified: 2008-01-09
How ?
I did succeed to import with bulk insert from ...
but I need to process that data and do the export by rewriting the text file as well.

Thanks.
Gregor
0
Comment
Question by:gregajesih
[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
  • 2
  • 2
4 Comments
 
LVL 34

Expert Comment

by:arbert
ID: 11930890
You can always use DTS and the sp_OA stored procedures to call it...
0
 
LVL 34

Accepted Solution

by:
arbert earned 1000 total points
ID: 11930915
(there is an example of SP_OA here--scroll down past the xp_cmdshell example http://www.databasejournal.com/features/mssql/article.php/1459181)

Brett
0
 

Author Comment

by:gregajesih
ID: 11939292
It seems there is nothing better (more elegant and simpler) then I accept the answer.
Thank you.
0
 

Author Comment

by:gregajesih
ID: 11942415
Well, I tried the approach and it seems that something is still not working.
I used this code with query analyzer being connected to the server and database where the source data is present and DTS package is stored in the same server under "ThisServer-DTS-Local packages".

MS-SQL Code:

-- create package
declare @hr int
declare @oPKG int
EXEC @hr = sp_OACreate 'DTS.Package', @oPKG OUT
IF @hr <> 0
BEGIN
    PRINT '***  Create Package object failed'
    EXEC sp_displayoaerrorinfo @oPKG, @hr
    RETURN
END

--Loading the Package:
-- DTSSQLServerStorageFlags :
--- DTSSQLStgFlag_Default = 0
--- DTSSQLStgFlag_UseTrustedConnection = 256
--EXEC @hr = sp_OAMethod @oPKG,
--  'LoadFromSQLServer("localhost","","", 256, , , , "ExportBsnprof",)',
--  NULL
EXEC @hr = sp_OAMethod @oPKG, 'LoadFromSqlServer', NULL,
  @ServerName='10.100.10.30\MPSCENTER', @ServerUsername='usernametext', @ServerPassword='passwordtext',@PackageName='ExportBsnprof', @Flags=256

IF @hr <> 0
BEGIN
    PRINT '***  Load Package failed'
    EXEC sp_displayoaerrorinfo @oPKG, @hr
    RETURN
END

--Executing the Package:
EXEC @hr = sp_OAMethod @oPKG, 'Execute'
IF @hr <> 0
BEGIN
    PRINT '***  Execute failed'
    EXEC sp_displayoaerrorinfo @oPKG , @hr
    RETURN
END
else
    print 'Executed!'

--Cleaning up:
EXEC @hr = sp_OADestroy @oPKG
IF @hr <> 0
BEGIN
    PRINT '***  Destroy Package failed'
    EXEC sp_displayoaerrorinfo @oPKG, @hr
    RETURN
END

..and here is the result grid text:

/*-----------------------------

-- create package
declare @hr int
-----------------------------*/
Executed!
 
What's wrong ?
Thanks.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

688 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