Search code examples
sqlcastingteradata

Teradata SQL Cast decimal to bigint


I am trying to run a select statement with 3 inner joins. The last join is a decimal to bigint conversion. I am trying to cast the decimal to bigint; however, I am still getting this error:

Error during Prepare S1000(-3754)[Teradata][ODBC Teradata Driver]Teradata DatabasePrecision error in FLOAT type constant or during implicit conversions. (0.29 secs)

Here is my query. I cannot understand what I am doing wrong. Can anyone help?

Select 
acct,
tramt,
TRINITDT,
trprocdt,
TRAN_CD,
TDDESC_1,
TDDESC_2,
MICM_TRAN_DESC,
LDGR_TYP_CD
from deposit.F_HRC_DPS_ACCT_TRAN_EOM as T

INNER JOIN customer.Cust_ACCT CA ON T.acct = CA.acct_NB 
inner join customer.CUST_IP_X_AR cipx on ca.cust_ar_id = cipx.cust_ar_id
inner join customer.cust c on Cast(cipx.cust_ip_id as bigint) = c.cust_ip_id
where Cast(cipx.cust_ip_id as int) in
(select top 50 Cast(cipx.cust_ip_id as bigint) from customer.cust)

update: I changed the inner join to this. Still same error.

INNER JOIN customer.Cust_ACCT CA ON T.acct = CA.acct_NB 
inner join customer.CUST_IP_X_AR cipx on ca.cust_ar_id = cipx.cust_ar_id
inner join customer.cust c on CAST(CAST(cipx.cust_ip_id AS numeric (27,0)) AS bigint)= c.cust_ip_id
where CAST(CAST(cipx.cust_ip_id AS numeric (27,0)) AS bigint) in
(select top 50 CAST(CAST(cipx.cust_ip_id AS numeric (27,0)) AS bigint) from customer.cust)

Solution

  • Use the CAST(CAST(column AS numeric (27,0)) AS bigint).

    Select 
    acct,
    tramt,
    TRINITDT,
    trprocdt,
    TRAN_CD,
    TDDESC_1,
    TDDESC_2,
    MICM_TRAN_DESC,
    LDGR_TYP_CD
    from deposit.F_HRC_DPS_ACCT_TRAN_EOM as T
    
    INNER JOIN customer.Cust_ACCT CA ON T.acct = CA.acct_NB 
    inner join customer.CUST_IP_X_AR cipx on ca.cust_ar_id = cipx.cust_ar_id
    inner join customer.cust c on CAST(CAST(cipx.cust_ip_id AS numeric(27,0)) AS bigint) = c.cust_ip_id
    where CAST(CAST(cipx.cust_ip_id AS numeric(27,0)) AS bigint) in
    (select top 50 CAST(CAST(cipx.cust_ip_id AS numeric(27,0)) AS bigint) from customer.cust)