sap-asesybase-ase15

Equivalent to WITH clause in Sybase ASE


It appears that WITH is supported only in Sybase SQL Anywhere: http://dcx.sybase.com/1100/en/dbusage_en11/commontblexpr-s-5414852.html

...but not in Sybase ASE :(

Can someone suggest if there is a equivalent construct in Sybase ASE? There are other ways to implement stuff instead of using WITH, but we are planning to repurpose some of our dynamically generated SQLs to run in Sybase and support for WITH or something close to that syntax is very much desired.


Solution

  • ASE doesn't have support for common table expressions (eg, WITH clause).

    The (obvious) workarounds would be #temp tables, views, materialized views (aka precomputed result sets), table variables (ASE 16.0 SP02+), and in limited situations possibly derived tables and/or (correlated) sub-queries.


    NOTE: I don't work with SQL Anywhere so not sure if this is technically doable but fwiw ...

    I'm thinking there's probably a way to setup a proxy table from SQL Anywhere to ASE, with the idea being to run your CTE/WITH query from within SQL Anywhere.

    'course, even if that's technically possible you're looking at the extra overhead for maintaining the SQL Anywhere database, and the performance for such interserver queries would likely be unacceptable (eg, pulling all the data from ASE into SQL Anywhere to, in effect, materialize the CTE).