Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Other SQL Server Topics (2005)
 Back Up some record

Author  Topic 

taniarto
Starting Member

27 Posts

Posted - 2013-03-04 : 21:33:29
Dear All,

I have 2 table the name is IVheader and Ivdetail. Ivheader is storing Sales header record (such id trans,date, total qty,total value) and ivdetail is storing transaction detail (such as id trans,itemid, qty, unit price and subtotal). I want to backup data from a range of record both of them. for example I want to back up transaction from '2013-03-01' until '2013-03-15' and than restore it again into another database on another location.
Does anyone can help ?

Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-04 : 22:54:00
are databases in same server? if yes, you can simply use INSERT...SELECT to insert required data from main table to your backup table. Then you may purge it from main table if you want. it will be like

INSERT INTO DB2.dbo.BackupTable
SELECT column1,column2,...
FROM DB1.dbo.MainTable
WHERE datefield >=@StartDate
AND datefield< @EndDate +1



also see here

http://visakhm.blogspot.in/2012/12/different-ways-to-implement-date-range.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

taniarto
Starting Member

27 Posts

Posted - 2013-03-05 : 03:50:53
does the syntax can be use for exporting the result into a text file and then import it again into database?
because it is different database and different location there's no connection between both of them..

thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-05 : 03:53:51
for that you need to use bcp or OPENROWSET
then you can again apply bcp in or BULK INSERT to insert it back

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -