SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Other SQL Server Topics (2005)
 Back Up some record
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

taniarto
Starting Member

Indonesia
27 Posts

Posted - 03/04/2013 :  21:33:29  Show Profile  Reply with Quote
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

India
52317 Posts

Posted - 03/04/2013 :  22:54:00  Show Profile  Reply with Quote
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

Indonesia
27 Posts

Posted - 03/05/2013 :  03:50:53  Show Profile  Reply with Quote
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

India
52317 Posts

Posted - 03/05/2013 :  03:53:51  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000