473,385 Members | 1,356 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,385 software developers and data experts.

COMMA delimited TEXT FILE

Hi,

On SQLServer 2000, I have a table with a following structure:

MYTABLE
col1 char,
col2 date,
col3 number

My Objective:
------------
Externally (from a command line), to select all columns and write the
output into a file delimited by a comma.

My method:
---------
1. Probably will use OSQL or BCP to do this.
2. Use the following syntax:
select RTRIM(col1) +','+ RTRIM(col2) +','+ RTRIM(col3)
from MYTABLE;

My 3 Problems:
-------------
1) If there is a NULL column, the result of concatenating any value with
NULL, is NULL. How can I work around this? I still want to record this
column as null. Something like say from the example above, if col2 is
null, would result to: APPLE,,5

2) The time format when querying the database is: 2003-06-24 15:10:20.
However, on the file, the data becomes: 24 JUN 2003 3:10PM. How can I
preserve the YYYY-MM-DD HH:MM:SS format? Notice that I also lost the
SS.

3) Which utility is better? BCP or OSQL?
For OSQL, it has a "-s" flag which gives me the option of putting a
column separator. But the result is:
"APPLE ,14 JUN 2003 , 5"
I don't need the extra space.
While for BCP, there is no column separator flag.

You will notice from my inquiry above that my background in SQLServer is
not very good.

Thanks in Advance!!

Regards
Ricky

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #1
1 13486
Hi ,

Suggested solution to your problems.

1) If there is a NULL column, the result of concatenating any value
with
NULL, is NULL. How can I work around this? I still want to record this
column as null. Something like say from the example above, if col2 is
null, would result to: APPLE,,5
Solution>> Use ISNULL T-SQL Function. In your case it will be
Select Filed1,Isnull(Field2,''), Field3 From TableName. This Isnull
function will replace value of field if null to supplied argument that
is ''.

2) The time format when querying the database is: 2003-06-24 15:10:20.
However, on the file, the data becomes: 24 JUN 2003 3:10PM. How can I
preserve the YYYY-MM-DD HH:MM:SS format? Notice that I also lost the
SS. Solution>> For 2nd porblem, change date time field value to varchar.
Thus query will be Select Filed1,Isnull(Field2,''), Cast (
DateTimeField3 as Varchar) From TableName.
Hope above hints help you.

Thanks, Amit
Ricky Cruz <sp*****@bigfoot.com> wrote in message news:<3e*********************@news.frii.net>... Hi,

On SQLServer 2000, I have a table with a following structure:

MYTABLE
col1 char,
col2 date,
col3 number

My Objective:
------------
Externally (from a command line), to select all columns and write the
output into a file delimited by a comma.

My method:
---------
1. Probably will use OSQL or BCP to do this.
2. Use the following syntax:
select RTRIM(col1) +','+ RTRIM(col2) +','+ RTRIM(col3)
from MYTABLE;

My 3 Problems:
-------------
1) If there is a NULL column, the result of concatenating any value with
NULL, is NULL. How can I work around this? I still want to record this
column as null. Something like say from the example above, if col2 is
null, would result to: APPLE,,5

2) The time format when querying the database is: 2003-06-24 15:10:20.
However, on the file, the data becomes: 24 JUN 2003 3:10PM. How can I
preserve the YYYY-MM-DD HH:MM:SS format? Notice that I also lost the
SS.

3) Which utility is better? BCP or OSQL?
For OSQL, it has a "-s" flag which gives me the option of putting a
column separator. But the result is:
"APPLE ,14 JUN 2003 , 5"
I don't need the extra space.
While for BCP, there is no column separator flag.

You will notice from my inquiry above that my background in SQLServer is
not very good.

Thanks in Advance!!

Regards
Ricky

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 20 '05 #2

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

Similar topics

4
by: Arne | last post by:
From: "Arne de Booij" <a_de_booij@hotmail.com> Subject: Comma delimited array into DB problems Date: 9. februar 2004 10:39 Hi, I have an asp page that takes input from a form on the previous...
4
by: Christine Forber | last post by:
I wonder if anyone knows of some javascript code to check a comma-delimited list of email addresses for basic formating. What I'm looking for is the javascript code to check a form field on form...
3
by: Elmo Watson | last post by:
I've been asked to develop a semi-automated type situation where we have a database table (sql server) and periodically, there will be a comma delimited file from which we need to import the data,...
1
by: DCM Fan | last post by:
Access 2K, SP3 on Windows 2K, SP4 All, I have an import spec set up with quoted Identifiers and comma-separated values. The text file is produced by a 3rd-party program of which I have no...
1
by: John B. Lorenz | last post by:
I'm attempting to write an input routine that reads from a comma delimited file. I need to read in one record at a time, assign each field to a field array and then continue with my normal...
2
by: Kenneth Koski | last post by:
Hello All, I have a comma delimited text file, which I would like to move into a SQL 2000 table . I created a DTS package in SQL Server and saved it as a VB.bas . I am writting the code in C#...
5
by: Yama | last post by:
Hi, I am looking to create a report comma delimited on a click of a button. Explanantion: 1. Get from the database: "SELECT * FROM Customers WHERE Region = 'CA'" 2. Use either DataReader or...
9
by: Bernie Yaeger | last post by:
Is there a way to convert or copy a .xml file to a comma delimited text file using vb .net? Thanks for any help. Bernie Yaeger
3
by: Avi | last post by:
I need to create a text file that has the data from the 10 tables in the database. The number of fields in the tables exceeds 255 and so I cannot make a new table with all the fields and then...
4
by: JustSomeGuy | last post by:
Hi. I have a comma delimited text file that I want to parse. I was going to use fscanf from the C library but as my app is written in C++ I thought I'd use the std io stream library... My Text...
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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.