3
Answers

insert two column values into one column

ajay raju

ajay raju

14y
6.2k
1

hi
how to insert two column values into another column. please give a query of that
means i take firstname and lastname and username in my table
username = firstname + lastname
how to write insert statement
all values are inserted same time
thanks.
Answers (3)
0
ajay raju

ajay raju

NA 384 0 14y

hi!
i find the solution of insert two column values into one column i.e., simple below is the code
create table users (firstname varchar(50), lastname varchar(50), username as lastname +  '  '  +  firstname)
insert into users values('Ajay','Kalidindi') // no need to write username column information it is automatically generated.
Thanks
 
0
Hirendra Sisodiya

Hirendra Sisodiya

NA 8.8k 3m 14y

hello ajay
i think we can not insert two coloumn value in to another column in single query. we can use update query after insert both values,this is very easy if your table has any identity column or any primary value like:
insert query:  insert into table(name1,name2) values(" Ajay ", " Raju ")
update query: update table set name3=name1+name2 where id=(select max(id) from table)
 
thanks
Please mark as answere if it helps
0
Jaish Mathews

Jaish Mathews

NA 7.3k 1.2m 14y

Hi,
Why can't you take a variable and store firstname + lastname. Then pass firstname,lastname and this new variable to a stored Procedure