Sumit Bisht
Sumit Bisht

Reputation: 1517

Casting column data type from varchar to int

I am trying to create a predictive analysis over a SAP HANA DB table containing multiple rows of what can be assumed to be transactions.
For this, I am using the apriori algorithm in the Predictive Analysis Library(PAL) to generate prediction of future instances of data.
However, I am having the row id as integer, but the other object's id as a varchar(although it contains numbers and is empty in very few cases).

    CREATE VIEW DATA_VIEW AS 
     SELECT "ID", "OBJECT_ID" 
      FROM "SCHEMA"."TABLE"
        ORDER BY "ID", "OBJECT_ID";

My question is, is there any way to cast the other id field into integer in the SAP HANA Database?
I need this format in order to supply the stored procedure in the AFLPAL for the APRIORI algorithm.
Or, is my approach totally wrong?

Upvotes: 0

Views: 7277

Answers (1)

schmerdy - Sonos
schmerdy - Sonos

Reputation: 151

use the TO_INTEGER (or TO_BIGINT if your Id's can get bigger) function. See http://help.sap.com/saphelp_hanaplatform/helpdata/en/20/ef488375191014888a939fbf0acd6b/content.htm

CREATE VIEW DATA_VIEW AS 
 SELECT "ID", TO_INTEGER("OBJECT_ID") 
  FROM "SCHEMA"."TABLE"
    ORDER BY "ID", TO_INTEGER("OBJECT_ID");

Upvotes: 2

Related Questions