Kalenji
Kalenji

Reputation: 407

Teradata SQL - Select to create a table

I am trying to get this one to work but not sure how to transfer from Sybase SQL to Teradata.

My code is the following for Sybase SQL.

SELECT
    d.dt

FROM (
Select CAST (dateadd(day, 0, getdate()) AS DATE) AS dt UNION ALL
Select CAST (dateadd(day,1, getdate()) AS DATE) UNION ALL
Select CAST (dateadd(day,2, getdate()) AS DATE) UNION ALL
Select CAST (dateadd(day,3, getdate()) AS DATE) UNION ALL
Select CAST (dateadd(day,4, getdate()) AS DATE) UNION ALL
Select CAST (dateadd(day,5, getdate()) AS DATE) UNION ALL
Select CAST (dateadd(day,6, getdate()) AS DATE) UNION ALL
Select CAST (dateadd(day,7, getdate()) AS DATE) 
) d

I tried below in Teradata but it is not flying.

SELECT
    d.dt

FROM (
Select CURRENT_DATE AS dt UNION ALL
Select (CURRENT_DATE - 1 )

) d

It works for today but as soon as I add UNION ALL and more days it gives me an error (3888)

Upvotes: 0

Views: 239

Answers (1)

Andrew
Andrew

Reputation: 8703

For me, the easiest way to do this on Teradata is fake it out with a simple 1 row CTE:

with cte as (select '1' as col1)

select
d.dt 
from (
Select CURRENT_DATE AS dt from cte UNION ALL
Select (CURRENT_DATE - 1 ) from cte
) d

Upvotes: 1

Related Questions