0

I have just created a simple query the concatenate 2 columns and create a column with this concatenation.

Now I want to ADD a new column to the table base on the below query

SELECT Convert(NVARCHAR(50), [cell_name]) + '_' + Convert(NVARCHAR(50), [n_cell_name]) AS st_gsm_df_relation_key FROM [myDB].[dbo].[gsm_df_relation] 

I want ALTER TABLE or something based on this query.

1
  • So what is your question here? Commented Jan 29, 2020 at 15:28

1 Answer 1

1

Use alter :

alter table table_name add st_gsm_df_relation_key_ as Convert(nvarchar(50),[cell_name])+'_'+Convert(nvarchar(50),[n_cell_name]); 

You can also use concat() :

alter table table_name add st_gsm_df_relation_key_ as concat(Convert(nvarchar(50),[cell_name]), '_', Convert(nvarchar(50),[n_cell_name])); 

concat() will ignore nulls when either cell_name or n_cell_name have null.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks alot that's actually what I need :) it was solved
@MahmoudAl-Haroon, it's good that you found a useful answer. Please consider accepting the answer by clicking on the grey check mark to the left. It rewards the person who answered with some reputation points, and you get some, too.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.