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

x
?
Solved

How to set options for MS SQL 2005 via isql in linux?

Posted on 2009-04-12
2
Medium Priority
?
1,194 Views
Last Modified: 2012-05-06
I regularly use MySQL, however am completely unfamiliar with MSSQL and the differences are killing me.
I have a task scheduled hourly to dump data from an Oracle database to a CSV file, which I then import into MySQL, I need now to do the same thing from a MSSQL 2005 database. All I need as results from the script are the comma separated values of the result of the query.
I need help converting the following Oracle script to be run from Debian 5.0 linux via iSQL on the command line, to be able to pull CSV data from MSSQL 2005.
SET FEEDBACK OFF
SET HEADING OFF
SET COLSEP ','
SET PAGESIZE 0
SET LINESIZE 5000
SET TERMOUT OFF
ALTER SESSION SET NLS_DATE_FORMAT='RRRR-MM-DD'
SET TRIMSPOOL ON
 
SPOOL /output/daily
SELECT FIELD1||','||
FIELD2||','||
FIELD 3 FROM TABLE WHERE CLAUSE;
SPOOL OFF
EXIT
QUIT

Open in new window

0
Comment
Question by:Madison_Hollister
[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 Comments
 
LVL 37

Accepted Solution

by:
momi_sabag earned 2000 total points
ID: 24128221
try this :

set nocount on
SELECT FIELD1+','+
FIELD2+','+
cast(Field3 as varchar(max))
FROM TABLE WHERE CLAUSE;

-- end of script

note - you will have to cast any non-character column as demonstrated for Field3
you will have to use linux shell to redirect the output to a file
you will need to remove the first 2 rows of the file (column headers and ----------------)
that's it (i guess, i never did it myself)

0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

661 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