473,382 Members | 1,665 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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.

Apr 9 '07 #1
2 4822
On Apr 9, 7:27 am, "Designing Solutions WD"
<michael.grass...@gmail.comwrote:
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

Apr 9 '07 #2
On Apr 9, 7:27 am, "Designing Solutions WD"
<michael.grass...@gmail.comwrote:
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

Apr 9 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Shawn Mehaffie | last post by:
I have the following class that I've wirtten to take a Dataset and automatically export it to either XML, ASCII or Tab delimited file. The reason I wrote it they way I did was that I don't want to...
1
by: Do Park via SQLMonster.com | last post by:
Hello all, I don?t often export data from a table. I am wondering how you export data from a table. I?d like to know how you export in real world. Do you export data from a table to a flat...
6
by: maricel | last post by:
Is there anybody out there who have any idea why EXPORT is relatively slower when putting the output file on a network drive - map drive from onother PC compared to putting it on my local PC drive...
1
by: Janne Ruuttunen | last post by:
Hello DB2 people, I'm having problems exporting >= 250000 lobs to IXF files with the LOBSINFILE option, using a legacy DB2 2.1 system on Win NT. If I don't specify a path for the lobs,...
4
by: Collin Peters | last post by:
I have searched the Internet... but haven't found much relating to this. I am wondering on what the best practices are for migrating a developmemnt database to a release database. Here is the...
5
by: Ryan Liu | last post by:
I have an application need export ane import data of projects. There are about 10 database tables releated to one project. 3 of them each could have up to 100K lines data. I can export all data...
1
by: chaitu | last post by:
Hi, Can anybody tell me what the error code for Export is. Like i get the message SQL3104N The Export utility is beginning to export data to file...
1
by: smaczylo | last post by:
Hello, I've recently been asked to work with Microsoft Access, and while I feel quite comfortable with Excel, I'm at a complete loss with databases. If someone could help me with this issue I'm...
4
by: Max2006 | last post by:
Hi, We are developing a SQL server based asp.net application. As part of requirement we should allow users import/export some relational data through web user interface. We are investigation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.