472,805 Members | 1,238 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 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 13453
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.