Sybase ASE 15.7 CTE to Subquery Issue

773 views Asked by At

This question is in regards to an earlier post of mine with code that I was running in SQL Server. I'm now using Sybase ASE 15.7 and am running into issues with the CTE. The error I'm getting is on the WITH part of the code below. I checked this post which states to use subqueries, but isn't that what I'm using anyways? I'm not all that familiar with CTE's.

The only change I made between SQL Server and Sybase was that I am using a temp table, #TEST1, instead of a real table.

What do I need to change in order to get the query to work?

WITH range
AS (
SELECT NM1 AS c FROM #TEST1
  UNION  
  SELECT NM2 FROM #TEST1
  UNION  
  SELECT NM3 FROM #TEST1
  UNION  
  SELECT NM4 FROM #TEST1
  UNION  
  SELECT NM5 FROM #TEST1)
SELECT r1.c, r2.c, r3.c, r4.c, r5.c
FROM range r1, range r2, range r3, range r4, range r5
WHERE r1.c<r2.c AND r2.c<r3.c AND r3.c<r4.c AND r4.c<r5.c
1

There are 1 answers

1
plankton On BEST ANSWER

I pivoted the original table which allowed me to eliminate the WITH section of the code. And now it works!