Unix Technical Forum

Best way to export data.

This is a discussion on Best way to export data. within the SQL Server forums, part of the Microsoft SQL Server category; --> Hello, I have some questions on my options available. I have to export some tables to csv files to ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-01-2008, 02:50 PM
Designing Solutions WD
 
Posts: n/a
Default Best way to export data.

Hello,

I have some questions on my options available.

I have to export some tables to csv files to enable another department
to process the files. What I need is a way to do this in ms sql
though a stored proc with quoted identifiers and column names as
heads. I cannot figure out how to do this.

Can anybody give me some options that would be the best options.

I am using ms sql 2000.

Thank you for your time.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-01-2008, 02:50 PM
klimenkor@gmail.com
 
Posts: n/a
Default Re: Best way to export data.

On Apr 9, 7:27 am, "Designing Solutions WD"
<michael.grass...@gmail.com> wrote:
> Hello,
>
> I have some questions on my options available.
>
> I have to export some tables to csv files to enable another department
> to process the files. What I need is a way to do this in ms sql
> though a stored proc with quoted identifiers and column names as
> heads. I cannot figure out how to do this.
>
> Can anybody give me some options that would be the best options.
>
> I am using ms sql 2000.
>
> Thank you for your time.


The easiest solution that came to my head is to execute DTS package in
command shell. In DTS package you can define whatever format you want.
Create it. Debug it. Play with it. Then just add xp_cmdshell
'dtsrun.exe -S<server> -N<dts-package> -E -M<dts-password>' to your
procedure.

- Roman

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-01-2008, 02:50 PM
klimenkor@gmail.com
 
Posts: n/a
Default Re: Best way to export data.

On Apr 9, 7:27 am, "Designing Solutions WD"
<michael.grass...@gmail.com> wrote:
> Hello,
>
> I have some questions on my options available.
>
> I have to export some tables to csv files to enable another department
> to process the files. What I need is a way to do this in ms sql
> though a stored proc with quoted identifiers and column names as
> heads. I cannot figure out how to do this.
>
> Can anybody give me some options that would be the best options.
>
> I am using ms sql 2000.
>
> Thank you for your time.


Straight forward solution is to UNION field names with data and use
BCP -

1. Create a SELECT statement that includes field names -
DECLARE @names varchar(100), @delimiter varchar(10)
SET @delimiter = ','
SELECT @names = COALESCE(@names + @delimiter, '') + '"' + name + '"'
FROM syscolumns where id = (select id from sysobjects where
name='TABLE_TO_EXPORT')

SELECT 'select ' + @names

2. Concatenate it with UNION SELECT cast(FIELD1 as char), cast(FIELD2
as char), .... From TABLE_TO_EXPORT (which is ugly but it has to be
done to create union)

3. Then using UNION create a VIEW which can be used in BCP to export
data

4. Use BCP from command shell xp_cmdshell "BCP ""select * from
VIEW_TO_EXPORT"" out c:\results.csv -c -t, -T -S<servername>

- Roman

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:56 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com