Developing for Dynamics GP

by David Musgrave (Perth, Australia) and Microsoft Dynamics GP Developer Support Team (Fargo, ND, USA)

Quick Tip: Copying small amounts of data in SQL Server quickly

Quick Tip: Copying small amounts of data in SQL Server quickly

Rate This
  • Comments 4

David Meego - Click for blog homepageLast week, I was working on a Microsoft Dynamics GP update case where we had to re-upgrade one company from the previous service pack to the current service pack.

To allow Dynamics GP Utilities to re-upgrade one company there are 3 things we need to do.

  1. Restore the previous version of the Company database.
  2. Restore the rows from the pre update data into DYNAMICS.dbo.DB_Upgrade table for the company.
  3. Restore the rows from the pre update data into DYNAMICS.dbo.DU000020 table for the company.

Well, the first step of restoring a database is fairly easy and won't be covered here.

The quick tip I will be covering is how to use the clipboard and cut & paste to copy data inside Microsoft SQL Server Management Studio.


This example is assuming that you have access to both the pre update DYNAMICS and the current DYNAMICS databases from Microsoft SQL Server Management Studio. This can achieved either by connecting to another SQL instance or by restoring the pre update DYNAMICS database backup into another database name.

Note: Before any direct editing of SQL data, it is recommended that you have backups of the database in case anything goes wrong.

The method is the same regardless of table, I will use the DU000020 table just because it has less columns and will be easier to create screenshots for.

In the source database (pre update DYNAMICS), right click on the dbo.DU000020 table and select Edit Top 200 Rows.

Then click the Show SQL Pane button to allow us to view and edit the SQL statement.

Change the SQL statement to add a where clause for the specific data we want to copy and then click the red exclamation mark to execute.

Now that the source data is displayed, click on the first row of the column to the left of the data (where the black right arrow is on the image above) to select the entire first row. The shift click the same button on the last row of the data (above the NULL row) to select the entire data set. Finally right click on the selected area and select Copy.

Now on the target database, locate the DYNAMICS.dbo.DU000020 table and select Edit Top 200 Rows and use the Show SQL Pane to add the where clause to the SQL statement and Execute the update code. Then select the data that you will be replacing using the same method discussed above (click and shift click on the left hand buttons).

This time right click and select Delete. It is important to remove the old data to avoid duplicate key errors when we paste in the new data.

Once the old data has been removed, click on the button to the left of the NULL line where the asterisk (*) is to select the entire line. Right click on the highlighted line and select Paste.

Voila, the data is pasted into the table. The trick that makes this work is selecting the entire NULL row before pasting.

Note: if you need more than 200 records, you can remove the TOP (200) restriction from the SQL select statement. However, be mindful that the clipboard is not the appropriate method to transfer gigabytes of data.

Hope you find this tip useful. It is definitely much simpler than using DTS (Data Transformation Services), SSIS (SQL Server Integration Services) or T-SQL to create an INSERT statement.

[Edit] For larger data sets have a look at this post: Quick Tip: Copying larger amounts of data in SQL Server quickly.

David

14-Feb-2012: Added mention of SSIS. Happy Valentines Day.

20-Feb-2012: Added link to follow up article.

  • DTS? That product shipped with SQL Server 2000. We're using SSIS since 2005 ;)

    Anyway, nice method. You could also use it to copy paste from Excel, to quickly create tables with test data for example.

  • Hi Koen

    Old habits die hard. Too used to calling it DTS.

    David

  • Posting from Mark Polino at DynamicAccounting.net

    msdynamicsgp.blogspot.com.au/.../quick-tip-copying-small-amounts-of-data.html

  • I really not recommend using this for result sets with many rows. But for small numbers of data this works fine.

Page 1 of 1 (4 items)
Comments Information

PLEASE READ BEFORE POSTING

Please only post comments relating to the topic of this page.

If you wish to ask a technical question, please use the links in the links section (scroll down, on right hand side) to ask on the Newsgroups or Forums. If you ask on the Newsgroups or Forums, others in the community can respond and the answers are available for everyone in the future.

Leave a Comment
  • Please add 7 and 3 and type the answer here:
  • Post