# Sybase automated export

**URL:** <https://forum.servoy.com/t/sybase-automated-export/7716>\
**Category:** Classic Servoy\
**Created:** [June 25, 2007, 1:13pm UTC](https://forum.servoy.com/t/sybase-automated-export/7716 "2007-06-25T13:13:36Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Westy](https://avatars.discourse-cdn.com/v4/letter/w/9de053/32.png) [@Westy](https://forum.servoy.com/u/Westy)\
**Post date:** [June 25, 2007, 1:13pm UTC](https://forum.servoy.com/t/sybase-automated-export/7716/1 "2007-06-25T13:13:36Z")

</div>

Can the following be run from a bat file or using the rawSQL plugin?

```auto
SELECT *
FROM contacts;
OUTPUT TO contacts.txt
FORMAT ASCII

```

If anyone can provide sample code for doing so with Sybase it would be greatly appeciated.

---

<div class="post-metadata">

**Author:** ![ngervasi](https://avatars.discourse-cdn.com/v4/letter/n/f9ae1b/32.png) [@ngervasi](https://forum.servoy.com/u/ngervasi)\
**Post date:** [June 25, 2007, 1:46pm UTC](https://forum.servoy.com/t/sybase-automated-export/7716/2 "2007-06-25T13:46:29Z")

</div>

> Westy:  
> Can the following be run from a bat file or using the rawSQL plugin?
> 
> ```auto
> SELECT *
> 
> ```

FROM contacts;  
OUTPUT TO contacts.txt  
FORMAT ASCII

> ```auto
> 
> If anyone can provide sample code for doing so with Sybase it would be greatly appeciated.
> 
> ```

You can use the rawSQL plugin, just double check if this SQL syntax is right for Sybase and keep in mind that the file will be created on the server and not on the client.

---

<div class="post-metadata">

**Author:** ![Westy](https://avatars.discourse-cdn.com/v4/letter/w/9de053/32.png) [@Westy](https://forum.servoy.com/u/Westy)\
**Post date:** [June 25, 2007, 2:48pm UTC](https://forum.servoy.com/t/sybase-automated-export/7716/3 "2007-06-25T14:48:18Z")

</div>

> ngervasi:  
> You can use the rawSQL plugin…

I am new to the rawSQL plugin. Is the following the correct syntax for putting the above multi-line statement on one line?

```auto
"SELECT * FROM contacts; OUTPUT TO contacts.txt FORMAT ASCII"

```

In other words, is it just a matter of inserting the “;” whenever a line break is required?

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [June 25, 2007, 3:02pm UTC](https://forum.servoy.com/t/sybase-automated-export/7716/4 "2007-06-25T15:02:34Z")

</div>

SQL ignores line-breaks, it treats them as spaces. And a semicolon is used when you want to execute your sql.  
So the following SQL are in fact 2 request send to the database:

```auto
SELECT * FROM contacts; OUTPUT TO contacts.txt FORMAT ASCII;

```

Hope this helps.

---

<div class="post-metadata">

**Author:** ![jhinsperger](https://avatars.discourse-cdn.com/v4/letter/j/919ad9/32.png) [@jhinsperger](https://forum.servoy.com/u/jhinsperger)\
**Post date:** [June 26, 2007, 12:23am UTC](https://forum.servoy.com/t/sybase-automated-export/7716/5 "2007-06-26T00:23:30Z")

</div>

I am not sure what the rawsql plugin is, but based on your commands, it looks like you are using the dbisql utility. The OUTPUT statement is a DBISQL only statement.  
You can run dbisql in batch mode to do what you want:  
eg. dbisql -c “connectstring” -nogui myfile.sql  
The file would contain the SQL statements you want to execute.

If you are on the same machine as the server, you could use the “UNLOAD SELECT” statement instead. This would probably work better from the “rawsql” tool.  
eg. UNLOAD SELECT \* FROM contacts to ‘filename’ format ASCII;

---

<div class="post-metadata">

**Author:** ![Westy](https://avatars.discourse-cdn.com/v4/letter/w/9de053/32.png) [@Westy](https://forum.servoy.com/u/Westy)\
**Post date:** [June 27, 2007, 2:31pm UTC](https://forum.servoy.com/t/sybase-automated-export/7716/6 "2007-06-27T14:31:21Z")

</div>

> jhinsperger:  
> You can run dbisql in batch mode to do what you want:  
> eg. dbisql -c “connectstring” -nogui myfile.sql

In the “C:\Program Files\Sybase\SQL Anywhere 9\win32” folder I created a executeSQL.bat file containing:

```auto
dbisql -c "uid=DBA;pwd=SQL" -nogui myfile.sql

```

In the same folder I created a myfile.sql file containing:

```auto
UNLOAD SELECT * 
FROM contacts
TO 'c:\temp\test.csv'
FORMAT ASCII

```

When I run the executeSQL.bat file I get the following error:

> Table ‘contacts’ not found

What should I be doing to help it find the ‘contacts’ table?

Dean Westover  
Choices Software, Inc.

---

<div class="post-metadata">

**Author:** ![ngervasi](https://avatars.discourse-cdn.com/v4/letter/n/f9ae1b/32.png) [@ngervasi](https://forum.servoy.com/u/ngervasi)\
**Post date:** [June 27, 2007, 3:02pm UTC](https://forum.servoy.com/t/sybase-automated-export/7716/7 "2007-06-27T15:02:58Z")

</div>

From the top of my head: try to prepend the name of the database like this:

```auto
SELECT * 
FROM myDBname.contacts; 
OUTPUT TO contacts.txt 
FORMAT ASCII

```

---

<div class="post-metadata">

**Author:** ![jhinsperger](https://avatars.discourse-cdn.com/v4/letter/j/919ad9/32.png) [@jhinsperger](https://forum.servoy.com/u/jhinsperger)\
**Post date:** [June 27, 2007, 8:14pm UTC](https://forum.servoy.com/t/sybase-automated-export/7716/8 "2007-06-27T20:14:39Z")

</div>

Here are a few things to check:

1. Is the DBA user the owner of the contacts table? If not, you need to prepend the table name with the owner name. (eg. owner.contacts). To find the owner, log in via dbisql and execute:  
SELECT table\_name, user\_name FROM SYSTABLE KEY JOIN SYSUSER ON SYSTABLE.creator = SYSUSER.user\_id WHERE SYSTABLE.table\_name=‘contacts’

2. Are you connecting to the right database? Your dbisql commandline only lists a UID/PWD and not a server name. This means you will connect to the first database server that was started on your local machine. To ensure you get connected to the right server, you should include the “eng” parameter. eg. uid=dba;pwd=sql;eng=myeng

3. As an extension to point 2), you can have multiple databases running on a single server. If you do, specifying uid=dba;pwd=sql will attempt to connect only to the first database that was started on the server. To ensure you are connecting to the right one, specify the dbn parameter: eg. uid=dba;pwd=sql;eng=myengine;dbn=mydatabase

If you have only one server running with one database, points 2 and 3 will make no difference.
