1

I would like to copy data from table a and insert it to the same table with a difference in one column.

For example: I have table a, with column name, I would like to :

insert into table a (name = 'daniel')
select * from table a  where phone = '000'

I would like the tran to take all columns in table a which phone is '000' and insert them again into table a the same, only the column name would be different.

Thank you

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

3 Answers3

1

Hope i understood the problem, if so here is the solution:

INSERT INTO table2 (column1, name, column3) SELECT column1, 'daniel', column3 FROM table2 WHERE phone = '000'

useful links:

Select, Modify and insert into the same table

https://www.w3schools.com/sql/sql_insert_into_select.asp

Kindly let me your thoughts or feedbacks thanks

karthik

Karthik Elumalai
  • 1,574
  • 1
  • 11
  • 12
0

Ya you can do with below lines

insert into table a (name ) select a.columa+' ' +b.columb as name from table a where phone = '000

If column have more Columbus than you can concate more Colums and insert into single column

NIts577
  • 420
  • 3
  • 13
0

My code by the answer :

select * from CatalogItems where UserId = 31406

begin tran
INSERT INTO CatalogItems (UserId,Code,Name,Price,PriceAfterTax,VatPercentage )
SELECT '31429',Code,Name,Price,PriceAfterTax,VatPercentage
 from CatalogItems WHERE userid  = 31406

 commit