4
Answers

insert two column information into one column

ajay raju

ajay raju

14y
7.1k
1

hi
i take 3 columns in my sql server table i.e., firstname, lastname,Contactname
i insert firstname and lastname then contactname is (firstname+lastname).
how to write the query.
i tried like
insert into contacts values ('ajay','kalidindi','(firstname+lastname)') but here display contactname is firstname+lastname.
please give a reply. urgent
thanks.
Answers (4)
0
Shambhu

Shambhu

NA 110 22.2k 14y
Hi Ajay,

You can get this by using store procedure because in direct insert sql statement column is not allowed to insert. So try this.

CREATE PROCEDURE SPContact
@FName varchar(20),
@LName varchar(20)
As
Begin
insert into contact(Fname, Lname, ContactName) values(@Fname, @Lname, @Fname+@Lname)
end
exec spcontact @Fname='Shambhu', @Lname='Suman'


Regards,
Shambhu


0
Venkatesan Jayakantham

Venkatesan Jayakantham

NA 11.9k 1.2m 14y

Check the below script,
drop
table venkat_table
go
create
table venkat_table (id int,val varchar(100),val1 varchar(100))
insert
into venkat_table values(1,'Venkat','Prabu')
select
ID, val +' '+ val1 as name from venkat_table
 
Cheers,
Venkatesan Prabu .J
 
0
Nikhil Mahajan

Nikhil Mahajan

NA 35 0 14y
just put simple query

insert into contacts values ('ajay','kalidindi',firstname+'-'+lastname)



0
Vasanth

Vasanth

NA 2.3k 309.6k 14y
Please check this ,


insert into contacts
select  'ajay',  'kalidindi',  (firstname + ' ' + lastname) as
contactname  from contacts where <filtercolumnname> = <filtervalue>



Please mark as answer if it helps you.