Federico Davide Federico Davide - 3 months ago 34
SQL Question

Teradata sql query with a case-SELECT Failed. 3706

I'm trying to create a query in Teradata but it gives me REPLACE VIEW Failed. 3706: Syntax error: expected something between ')' and ','.

replace VIEW view as
select

a.ID_CD,
a.SEX ,
x.BIRTHDATE as BIRTHDATE_DT,
case when (substring((x.cfisc_de), 12 , 5)=' ') then x.cfisc_de else null end as PIVA_CD,
case when (substring((x.cfisc_de), 12 , 5)<>' ') then x.cfisc_mask_de else null end as CFISC_CD,



FROM table1 a
INNER JOIN table2 x
ON a.ID_CD=x.ID_CD

Answer

Teradata supports two variations of substring:

SUBSTRING(col FROM n FOR m)
SUBSTR(col, n , m)

You wrote a mixture of both. Depending on some ODBC settings this might work (it's automatically changed to valid SQL by the ODBC-driver, but only within a SELECT), but will fail in a CREATE or using .NET/JDBC/CLI.