Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 14th, 2005, 05:15 PM
Registered User
 
Join Date: Dec 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default How do I append a single record ???

Hi guys,
          I wanted to know how to append only a single record from one table to another.I jus want to append certain fields. Could someone help me. I have been stuck for sometime now.Thank you.
 
Old December 14th, 2005, 05:18 PM
Authorized User
 
Join Date: Sep 2005
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Don't know if I understood your question correctly

insert into TableA
select * from TableB where id =1

this will insert only 1 record (where the id =1) into tableA, of course the table structure has to be identical




“I sense many useless updates in you... Useless updates lead to fragmentation... Fragmentation leads to downtime...Downtime leads to suffering..Fragmentation is the path to the darkside.. DBCC INDEXDEFRAG and DBCC DBREINDEX are the force...May the force be with you" -- http://sqlservercode.blogspot.com/
 
Old December 14th, 2005, 05:26 PM
Registered User
 
Join Date: Dec 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for replyin soon.
                          I wanted to append based on the current key.The source and destination tables r linked and i wanted to append the record when
                DestinationTable.ForeignKey=Sourcetable.PrimaryKey

Hope this question is more detailed.Thanks though.Realy appreciate the effort.

 
Old December 14th, 2005, 05:40 PM
Authorized User
 
Join Date: Sep 2005
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
Default

insert into DestinationTable
select c.* from Sourcetable c left join DestinationTable d
on d.ForeignKey=c.PrimaryKey
where d.ForeignKey is null

This will insert all the records into DestinationTable that exist in the Sourcetable but not in DestinationTable
you can limit the records by using TOP

“I sense many useless updates in you... Useless updates lead to fragmentation... Fragmentation leads to downtime...Downtime leads to suffering..Fragmentation is the path to the darkside.. DBCC INDEXDEFRAG and DBCC DBREINDEX are the force...May the force be with you" -- http://sqlservercode.blogspot.com/





Similar Threads
Thread Thread Starter Forum Replies Last Post
append record whith do while function iisha64 Access VBA 0 February 19th, 2007 09:24 AM
last or curremt record append queries mohiddin52 Access VBA 7 January 19th, 2007 08:28 AM
Help in appending a single record. prashanthmcr SQL Language 0 December 14th, 2005 08:47 PM
"Single-Record" Recordset Wyatt70 Classic ASP Databases 2 November 18th, 2003 01:20 PM
Display a single record.. PLEASE HELP TnTandyO Classic ASP Databases 26 September 9th, 2003 10:34 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.