DEV Community

Query Filter
Query Filter

Posted on

dump

ybase bcp supports exporting results of a SQL query, not just entire tables.

Example: dump last 45 days from table MYTABLE with timestamp column INTERNTIMESTAMP.

bcp "select * from MYTABLE
where INTERNTIMESTAMP >= dateadd(dd, -45, getdate())"
queryout mytable_45days.dat -c -U user -P pass -S server

Notes:

queryout lets you export results of a query.

-c uses character mode (good for Oracle import).

Make sure dateadd() and getdate() match your Sybase SE syntax (SQL Anywhere uses dateadd('day', -45, now())).

For SQL Anywhere (Sybase SE):
dbisql -c "uid=user;pwd=pass;eng=mydb" ^
"select * from MYTABLE
where INTERNTIMESTAMP >= dateadd( day, -45, current timestamp )"

mytable_45days.csv

or using dbunload with -x and -s filters (below).

✅ Option 2 — SQL Anywhere: Use dbunload with row filter

SQL Anywhere (Sybase SE) has a flexible unload tool:

dbunload -c "uid=user;pwd=pass;dbf=my.db" ^
-s "select * from MYTABLE where INTERNTIMESTAMP >= dateadd(day, -45, current timestamp)" ^
myexportdir

This creates:

mytable.sql with table schema,

mytable.dat with only filtered rows.

Perfect for Oracle import.

Top comments (0)