Re: how to add an new record from part of an old one
От | George Moga |
---|---|
Тема | Re: how to add an new record from part of an old one |
Дата | |
Msg-id | 3B03DFF4.FB6BAF6E@dsn.ro обсуждение исходный текст |
Ответ на | how to add an new record from part of an old one (juerg.rietmann@pup.ch) |
Список | pgsql-sql |
juerg.rietmann@pup.ch wrote: <blockquote type="CITE">Hi there <p>I need to half copy and insert new data in a new record.Please see the SQL <br />statement, that is not working, but i think is shows what I'd like to do. <br />The fieldsa_nr and a_kurzbez will get the values from a form and a_bez <br />needs to be copied from an existing auftrag. <p>Thanksfor any help ... jr <p>insert into auftrag (a_nr, a_kurzbez) values (123456789, 'testtext') <br />(select a_bezfrom auftrag where a_nr='200113672732')</blockquote><p><br />Try something like the folowing example: <p><tt>test=#create table a (id serial, a1 text, a2 int4);</tt><br /><tt>CREATE</tt><br /><tt>test=# insert into a (a1, a2)values ('1221211', 12);</tt><br /><tt>INSERT 580415 1</tt><br /><tt>test=# insert into a (a1, a2) values ('12345', 11);</tt><br/><tt>INSERT 580416 1</tt><br /><tt>test=# select * from a;</tt><br /><tt> id | a1 | a2</tt><br /><tt>----+---------+----</tt><br/><tt> 1 | 1221211 | 12</tt><br /><tt> 2 | 12345 | 11</tt><br /><tt>(2 rows)</tt><br/><tt> </tt><br /><tt>test=# create table b (id serial, b1 text, b2 int4, b3 varchar(32));</tt><br /><tt>CREATE</tt><br/><tt>test=# insert into b (b1, b2, b3) select a1, a2, 'something else' from a where id = 1;</tt><br/><tt>INSERT 580468 1</tt><br /><tt>test=# select * from b;</tt><br /><tt> id | b1 | b2 | b3</tt><br/><tt>----+---------+----+----------------</tt><br /><tt> 1 | 1221211 | 12 | something else</tt><br /><tt>(1 row)</tt><br/><tt> </tt><br /><tt>test=#</tt><p>I hope this can help you !! <p>George Moga, <br /> Data Systems Srl <br/> Slobozia, ROMANIA <br /> <br />
В списке pgsql-sql по дате отправления: