cancel
Showing results for 
Search instead for 
Did you mean: 

SAP HANA Table Calculated field

former_member290321
Participant
0 Kudos

I have table A which has First Name and Last Name as fields with ClientId as Primary Key,

	 CREATE COLUMN TABLE NAME("FIRSTNAME" VARCHAR (50) null,
	 "LASTNAME" VARCHAR (50) null,
	 "SRNO" INTEGER GENERATED ALWAYS AS IDENTITY (START WITH 100 INCREMENT BY 1));

	 

Need to add a calculated field 'FullName' (FirstName + Last Name) at table level so don't have to created calculated column in calculation view. The table has around 40 million records.

CREATE COLUMN TABLE NAME ("FIRSTNAME" VARCHAR (50) null,
	 "LASTNAME" VARCHAR (50) null,
"FULLNAME" VARCHAR (100) null (Need this field as a calculated field i.e FIRSTNAME +LASTNAME) ,
	 "SRNO" INTEGER GENERATED ALWAYS AS IDENTITY (START WITH 100 INCREMENT BY 1));

	 

Accepted Solutions (1)

Accepted Solutions (1)

former_member290321
Participant
0 Kudos

Here you go...

--Create Table 
CREATE COLUMN TABLE "HANAUSER"."NEWTABLE"(
     "FIRSTNAME" VARCHAR (50) null,
	 "LASTNAME" VARCHAR (50) null,"SRNO" INTEGER GENERATED ALWAYS AS IDENTITY (START WITH 100 INCREMENT BY 1)
	 );
	 
--Insert
insert into "HANAUSER"."NEWTABLE" values('NICK','DURAN');
insert into "HANAUSER"."NEWTABLE" values('H','CLITON');
insert into "HANAUSER"."NEWTABLE" values('D','TRUMP');
insert into "HANAUSER"."NEWTABLE" values('M','GUID');

--Select
Select * from "HANAUSER"."NEWTABLE";

Alter table add calculated field

--Alter table with calculated field 
ALTER TABLE "HANAUSER"."NEWTABLE" add ( "FULLNAME" VARCHAR(30) GENERATED ALWAYS AS ("FIRSTNAME" ||"LASTNAME"));


--Select
Select * from "HANAUSER"."NEWTABLE";

My finding generated column is way better than calculated column if data volume is very large, In my case its just a concat of two column pretty straight forward.

Thanks

Answers (2)

Answers (2)

former_member290321
Participant
0 Kudos

I am loading table with SLT and I can add a concat field at the time of loading through SLT but don't want to change SLT at this point of time.

Yes I can do the same in Information view i.e In Calculation View as a calculated column but then it will use analytical engine as well as olap engine and will create a temp table which will impact performance.

If I can add at the table level without changing anything in SLT which I can easily do in other database it will be awesome.

I am looking for Default something like that

Jan_van_Ansem
Contributor
0 Kudos

Not sure what you are trying to do here.

You have a create statement for a table, but you haven't specified how you are going to populate the data.

Are you uploading it from file, creating it from another table?

Anyway, I wouldn't bother to create a column which physically holds the concatenation of two fields.

You can save yourself some space and concatenate the two fields in a view, either a SQL or Calculation view, with a simple formula.