on 11-12-2015 4:33 PM
It is requested to export data from ASE in a csv file having all the data quoted. In Interactive SQL GUI we can use this
OUTPUT TO 'C:\tmp\data.csv' FORMAT ASCII
DELIMITED BY ',' QUOTE '''' ALL ENCODING cp1253
GO
and it returns the desired result. However we cannot create a script executed from command line that produces this file, because the GUI dbisql cannot take any arguments in order to connect to an ASE instance and execute an SQL file and the command line isql cannot accept the output command. I think we cannot achieve this using only the ASE client tools
A supposed solution could be to create a string for each row and export it using bcp or even isql. I would prefer to avoid such an approach.
Thank you in advance
Both bcp and isql can create rows where columns are separated by tab.
This typically suffices for exporting to excel etc.
You can also use some other character like '|" pipe symbol or "~" tilde etc. to separate columns. When you import in excel you can use that as a column separator.
For bcp use character mode output, tab is default column separator.
For isql space is the default column separator
If you want to use different column separator (e.g. "|" ) then
for bcp use -c -t '|' option
for isql use -s '|' option
Output of isql and bcp can be directed into a file. Similar to what you describe above.
You can also easily script wrappers to accept server, database and table/view names to run for a specific purpose.
HTH
Avinash
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Kimon,
are you speaking about this interactive SQL tool?
If yes then you should be able to connect via script .
HTH
DJ
You are welcome to look out for a third party tool
Being a passionate developer, I tend to use the lego blocks provided first !!
So while you are looking for the tool,
you can use powerful object called view !
view also allows you projections (set of columns) and selection (set of rows) and rearrange the columns, column names, etc.
Both bcp and isql can get data out from a view.
As an example : To get 4 coulmns out of master..syslogins
create view v_mysyslogins
as
select
'"' + name + '"' as name,
'"' + convert(varchar(5), suid) + '"' as suid,
'"' + fullname + '"' as fullname,
'"' + convert(varchar(30), crdate, 109) + '"' as crdate
from master..syslogins
go
Sample output is :
1> select top 3 * from v_mysyslogins
2> go
name suid fullname crdate
-------------------------------- ------- -------------------------------- --------------------------------
"sa" "1" "" "Nov 18 2010 4:16:10:886PM"
"probe" "2" "" "Nov 18 2010 4:16:35:026PM"
"locke" "4" "" ""
(3 rows affected)
And you can use isql or bcp to get data using this view.
You can also craft your script(s) to automate creation of this type of views on the fly by providing just the table name.
HTH
Avinash
Don't confuse 'isql' which is the command-line tool that comes with ASE with 'DBISQL or dbisql' (Interative SQL GUI) that comes with ASE, IQ and SQL Anywhere.
You are refererencing dbisql/DBISQL in your use of 'output' statements, which 'isql' does not use.
Also from some of the other responses, there is no reason that you cannot use other delimiters (e.g. tab, '|', etc) in the BCP tool (even through views) to output the data.
Tools such as Excel can easliy import different delimiters and ignore the double quotes. Often other delimiters are used as sometimes the data also contains double quotes (and then you need to find a way to 'escape' the embedded quote). Better to just skip needing double quotes around the strings and use a different delimiter that doesn't show in the data.
Are you sure you really need double quotes around strings and commas as the delimiter? What is the file being generated for?
Chris
Have you tried calling 'dbisql' with the '-nogui' option (along with -'c ...) and passing the script?
If you are using this to extract hundreds of thousands of rows then there is definitely something wrong here as other things, such as network traffic to the dbisql client, will impact performance (you can set a larger server packet size for this).
How often is this being performed? Are the 'reports' only extractions or the results of SQL queries? What is the destination system - is it another database?
Have they looked at other tools such as Data Services or SRS?
Chris
Thank you Chris for your effort. Actually they are supposed to have realized these risks. Actually dbisql manages to create such big files running locally on the ASE machine. Concerning the -nogui option I have tried and failed to write a valid -c connection string for ASE. Even when using DSN it fails to connect
Any ideas on this is welcome.
Kimon
Using the output command as per your example, create a file sql.sql containing something like:
select 1
go
output to 'c:\temp\output.txt' FORMAT ASCII
DELIMITED BY ',' QUOTE '''' ALL ENCODING cp1253
Then run:
# ./dbisql -host <host> -port <port> -c "UID=<user>;PWD=<pwd>" -nogui sql.sql;cat /cygdrive/c/temp/output.txt
'1'
User | Count |
---|---|
78 | |
9 | |
9 | |
7 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.