views:

83

answers:

2

I have two tables

create table p
(
  x number,
  y number,
  z number
);


create table q 
(
  a number,
  b number,
  c number,
  d  varchar2(20)
);

I have inserted

insert into p values('1','2','3');

now i need to insert into q selecting values from p with last field getting name like Table _name in table q

values such that table q contains

a  b  c  d
1  2  3   table_name

plz help as soon as possible

+1  A: 

INSERT INTO q(a, b, c, d) SELECT x, y, z, 'table_name' FROM p

tzup
thanx it worked for me thanx to every body
You're welcome! Please choose an answer as the accepted answer.
tzup
A: 
CREATE TABLE TestTable (FirstName VARCHAR(100), LastName VARCHAR(100))

INSERT INTO TestTable (FirstName, LastName)
SELECT FirstName, LastName
FROM Person.Contact
WHERE EmailPromotion = 2
SELECT FirstName, LastName
FROM TestTable

DROP TABLE TestTable

http://blog.sqlauthority.com/2007/08/15/sql-server-insert-data-from-one-table-to-another-table-insert-into-select-select-into-table/

Bhaskar