0

I want to generate a list like -3, -4, -5, -6, -7 in Teradata Sql asst. Is there any direct way to do it. Sample attached here.enter image description here

1 Answer 1

0

In Teradata, there isn't a built-in function for generating a sequence of numbers. However, you can achieve this by using a recursive cte as follows:

WITH RECURSIVE nums AS
(
  SELECT -7 AS n FROM DBC.DBCInfoV WHERE InfoKey='Version' -- or from any table you already have
  UNION ALL
  SELECT n + 1 FROM nums WHERE n < -3
)
SELECT * 
FROM nums
ORDER BY n DESC
Sign up to request clarification or add additional context in comments.

3 Comments

This won't run in teradata. The union requires an actual table. Easy enough to get around with a volatile table though.
Or just add any FROM / WHERE clause to the initial SELECT that returns a single row. For example FROM DBC.DBCInfoV WHERE InfoKey='Version'
I have edited my answer, Thank you all For the help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.