Copying Data

Oct 10, 2006

Rene writes "Good evening. This is my first time using sqlteam for answers and I'm hoping I can get some much needed direction.

Basically what I am trying to accomplish is taking records from a temporary source table to a permanent table. Here is what the tables look like (oversimplistic version)

tblTemp

ID
Value1
Imported
FailedReason


tblPerm

ID
Value1


Basically I would like to take the values from tblTemp and INSERT them into tblPerm. The catch is that values in tbltemp might violate primary key constraint because of duplicate values in the ID field. The value1 field is required in tblPerm and it might contain a null value on tbltemp causing the insert statement to fail.

What I would like the end result to be is that any records which are INSERTED from tbltemp to tblperm are flagged with a value of imported=1 on the tbltemp table. Any records which fail should then be flagged as imported=0 and failedreason=reason for failing.

I am trying the following to start with but am not sure if I am steering in the right direction or not. The process should be as automated as possible, perhaps part of a scheduled dts package or likewise since new data will be inserted in the tbltemp table on a weekly basis.


set rowcount 1

update tblsource set imported = 0 where imported is null

insert into tbldest (col1, col2)
select top 1 col1, col2 from tblsource where imported = 0 and notimportreason is null

IF @@Error <> 0
GOTO ErrorHandler

UPDATE tblsource SET imported = 1 where imported = 0 and notimportreason is null

ErrorHandler:

update tblsource SET notimportreason = @@error where imported = 0 and notimportreason is null


RETURN"

View 2 Replies


ADVERTISEMENT

Copying Data Problem With Export Data Tool

Nov 14, 2007

I Have a problem when copying data from one server to another in Management studio, I need to create and exact copy of the original because of primary key relationships,

Currently when I export the data the data will run through an insert type statement, which means that all PKs are reissued, rather than being duplicated from the original, How can I be sure that the data will be copied exactly how it is on one server to the other.

View 4 Replies View Related

Error Copying Data Using Data Tranformation Process

Jan 2, 2008

i've created a package that will copy data from an oracle table to a sqlserv table (that table elemenst are identical), when i click on the connecting line between the two connections it executes without any errors, but nothing is copied, when i try to execute the package i'm getting an error... where can i go to find out what's causing the error. There is no error message or number returned from dts, all i get is a red 'x' . There are 1236 records that need to be inserted and when i get the red 'x' it tells me 1236 records have been processed. When i click on tranformations and select test, it works, but since it's a test nothing is actually copied. I've got other packages that i've created that do the same thing with other tables and they work. I tried just copying one record and that worked, so i assumed it must be data dependent, i've checked all the fields and made sure they weren't null, i've checked to make sure there aren't duplicate primary key records. Without knowing what the actual error is I'm stumped ???

View 4 Replies View Related

Copying Data From One Table To A New One With Some Different Data Types

Mar 30, 2007

Is it possible to easily copy data from one table to another if the data types don't match.   I know you can do a INSERT INTO table1(col1,col2)  SELECT (col2,col7) FROM table2 if the data types match but is there a way to do this if they don't. I'm not trying to copy date times into bit fields or anything.  I just have an old table that I built when I really didn't know what I was doing now I at leastthink I have a better understanding of what data types to use, so I was wanting to move the data in the orignal table to my new one.  Most of the fields in the olddatabase are text datatypes and the new database is nvarchar(50) data types.  Thanks for any suggestions. 

View 4 Replies View Related

Copying Data From PRD To TST

Apr 28, 2006

I've got two DBs in the same SQL instance. They are named TST and PRD. I am using 2.0 so there are many ASP generated tables also. Every once in a while I want to refresh data from PRD to TST. But I don't want to copy the data from ASP tables.What is the easiest way to do so?

View 6 Replies View Related

Copying Data WITHOUT DTS

Mar 10, 2008

HiWe use Sql Server 2000.Is there a way to copy and entire text file into a database tablewithout using a DTS ?

View 2 Replies View Related

No Data After Copying

Nov 1, 2007



HI,

I just copied sm data from a table in a DB to a flat file which I have created previaouly in my documents in my local machine.
I used the following command.

C:Documents and Settingsshamen> dbname.tablename out flatfile.txt -T


Once I run this it prompted two questions asking pre-fix lenght and field terminator. I jsut accepted the default values.
After I run it, it copied data. But when I see the flat file , I did not see data in that file.
To where data has been copied?

it says 10000 rows succesfully bulk-copied to host file. Total received 6176000.
But I dont see data there now.

View 5 Replies View Related

Copying Tables And Data

Jul 25, 2007

Is there any simple way to copy tables from one database to another in SQL Management Studio or VS 2005?  I sometimes work split work between home and work and I often need to copy and table and its data (data, stored procedure, etc) to a different database, but having to create a new database then copy the data is a pain.  Is there an easier way? 

View 5 Replies View Related

Copying Data Between Databases...

Sep 2, 2002

If I have to copy data from one database to a temporary database on the same server, which transaction log will be written to as a result? Will it be the DB that the command is run from, the source DB, or possibly tempdb's log?

Thanks

Derek

View 1 Replies View Related

DTS - Copying Table Data

Oct 31, 2004

hi all,

i have a dts that copies table contents from remore server to local server.
remote table:
ItemID|name
1 |name1
2 |name22
3 |name33

local table:
ItemID|name
1 |name1
2 |name2

i want that the dts will only copy the new rows( aka. row with ItemID = 3) and leave the other rows a they are.

can any one help me create such a dts.



please help!

View 1 Replies View Related

Copying Table And Data

May 1, 2007

Hi All

Iam using sql 2005 and am new to it, I want to copy a table and data from server to another, how is this possible?

Many Thanks in advance....

View 2 Replies View Related

COPYING Data Between Databases.

Oct 16, 2007

Hi All,
I wish to copy between 2 tables in different databases.
( The source and destiantion tables already exist)
The source table has duplicate entries which i want to avoid from being copied to destination table.
How can i achieve this?

Thanks in advance..!!
Vishu

View 20 Replies View Related

Copying Data From SQL2000 To DB2 8.1

Jul 20, 2005

I have to setup some scheduled tasks to copy 3-4 tables from anSQL2000 database to DB2 v. 8.1.The job must run every night replacing all data.How can this be done - with standard utilities??Please be exact - I'm new to this.Thank for any help./Jep

View 1 Replies View Related

Copying Data From One DataBase To Another?

Jan 25, 2007

Yet another very much newbie question I suspect€¦.

I want to know how I copy data from one field in one
DataBase to another field in another DataBase??

Basically I have an ASP driven forum, and want to upgrade to
a new ASP.NET forum€¦ Problem is obviously the DataBase structure is different
and I don€™t want to loose all the data from my current forum€¦ So I would have to pick which table field
needs to be copied to where in the new DataBase..

Is this easy to do??
I will be using SQLExpress 2005??

Thanks

View 1 Replies View Related

Copying Database Without Data

Jun 13, 2005

Hi,

View 5 Replies View Related

Moving/Copying Data

Oct 4, 2007

Hello everyone!

I have two servers, one is 2005 standard, the other is 2005 express.
I'm using express to record test results and it will be keep recording non-stop.
So, what I want to do is I want to transfer data from express to standard using SSIS package, and as soon as data gets transferred the data to no longer exists in express.


I have a job running the "copy" package every minute, but I don't know how to delete the data in express.
Does anyone know how to help me out pleaseeeee..?



Thanks in advance.


MIKE!

View 6 Replies View Related

Copying Row Data Within The Same Table

Apr 3, 2006

I have the following table:

Table name: RR

columns:

Subject (varchar (35), Null)

Topic (varchar (35), Null)

RD (text, null)

RR (text, null)

Picture (varchar (50), Null)

Video (varchar (50), Null)

RRID (int, Not Null)

TSTAMP (datetime, Null)

RRCount (int, Not Null)

This table stores common information used in resolving technical problems based on Subject and Topic. However, I've now created a Subject/Topic where I want to copy all the data that corresponds to another Subject/topic.

Example:

There are 35 rows that correspond to Subject = 'Publisher01' and Topic = 'Subcategory03'. I want to create 35 new rows that contain the same RD and RR data, but have Subject = 'Publisher02' and Topic = 'Subcategory07'. Highest current RRID = 5008

I cannot figure out how to write that query. I apologize in advance for the fact that this is, no doubt, a seriously beginner question.

View 1 Replies View Related

Copying SQLDataSource Data Into DataSet

Feb 2, 2007

is there a way to copy a SqlDataSource Data into a dataset?

View 4 Replies View Related

Copying Data From Another DB On Server Problem

Mar 2, 2005

What iam trying to do is put the table name from one db into a variable and another one into another variable and pass them into my statement basicaly trying to bulk copy data from one table in a db and insert it into another db on the same server based on a condition

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ClientComment]')
and OBJECTPROPERTY(id, N'IsUserTable') = 1)

Declare @BDFR varchar(20), @BDTO varchar(20), @EQID varchar(20)
set @BDFR = 'Commander' + '.dbo.' + 'ClientComment'
set @BDTO = 'Test_Commander' + '.dbo.' + 'ClientComment'
set @EQID = '80_300_005'
insert into @BDTO
select * from @BDFR where Eqid = @EQID

View 2 Replies View Related

SQL 2012 :: Copying Data Between Tables

Apr 15, 2015

We've had a new server set up with SQL 2012 and I'm in the process of moving data to it from a 2008 (SP2) server.

Details are as follows:-
2012 instance:- Microsoft SQL Server 2012 - 11.0.5058.0 (X64)
May 14 2014 18:34:29
Copyright (c) Microsoft Corporation
Standard Edition (64-bit) on Windows NT 6.3 <X64> (Build 9600: ) (Hypervisor)

2008 instance:- Microsoft SQL Server 2008 (SP2) - 10.0.4000.0 (X64)
Sep 16 2010 19:43:16
Copyright (c) 1988-2008 Microsoft Corporation
Standard Edition (64-bit) on Windows NT 6.1 <X64> (Build 7600: ) (VM)

I don't want to do a backup/restore routine as there are collation conflicts on the 2008 server.I've created the database and tables on the 2012 instance and now I want to transfer the data from the 2008 instance to the 2012 one.

The 2012 instance has a linked server to the 2008 instance.I was trying to use sp_MSForEachTable (I know, it's old and will probably disappear shortly) but that doesn't seem to work properly because some of the columns have an Identity field set up.

Some of the tables have upwards of 10 million records in them and are quite sizeable.how I can achieve the transfer without a back-up/restore?

View 9 Replies View Related

Copying Data From One Database Table To Other

Oct 25, 2005

hi all

i have two databases on two different machines.

both databses r having same names.

i want to copy data from the table in other database to table in databse on my machine .

how can i do this.

i will be very thankful to receive help.

View 2 Replies View Related

Copying Data Into Another Table Using A Stored Pro

Apr 19, 2007

Can i do something like this

INSERT INTO CITIBANK.dbo.Contract (*)
FROM exec sp..

where sp is the stored procedure ?

Or do i need to specify all the colums where the * is ?
and if so is it the columns from the SP or the colums
from the destination table ?

View 4 Replies View Related

Copying Data And Structure From One Database To Another

Jul 23, 2005

Hi all!I have an application that needs to copy the database structure fromone database to another without using the "Generate SQL Script"function in Enterprise Manager. I'd like to do this from within astored procedure. Can someone recommend the best approach for this?I've seen references to using SQL-DMO from a stored procedure using thesp_OA* procs in other postings to this group but was wondering if therewas an easier way? Can I use bcp and then use xp_cmdshell from withinmy stored procedure? It's not clear to me from the documentationwhether bcp copies both structure and data or just data? Is there abetter way?Thanks in advance for any help!Karen

View 1 Replies View Related

Copying Data Between Database Tables

Sep 7, 2006

Hi. I need to move data from one database table to
another across database instances. A simple example of the typical
move would be:



[CODE]

INSERT into destination_db.dbo.table1

SELECT column1, column2, column3, column4 from source_db.dbo.table2

[/CODE]



My options are:



1. Create an SSIS package to perform the move.

2. Create sprocs and schedule the data move as jobs.

3. Write .NET code using sprocs to perform the move.



I'll have to move hundreds of thousands of records, so I want the
option that provides the best performance. I'm guessing that option 3
will be the slowest.



Thanks for the help!

View 4 Replies View Related

Errors Copying Data Base

Jul 24, 2006

I'm trying to copy a data base from one server to another. Both servers are running 2005 MSDE, on Win 2k3, the target server is 64 bit.

I'm using the Copy Database function, and ultimately it fails with the error in the event viewer in the targe machine:

Faulting application dtexec.exe, version 2005.90.1399.0, stamp 43500d1a, faulting module kernel32.dll, version 5.2.3790.1830, stamp 42438b79, debug? 0, fault address 0x0000000000027d0d.

I have tried both the Attach/Detach & the SMO method, and they both give me the same error. I have 'Repaired' the .NET framework on the target machine, with the same result.

Does anyone have any Suggestions? I really only need at this time to make one copy of the database.



Thanks

Phil

View 5 Replies View Related

Data Not Copying To MS Access Table

Aug 27, 2007

Hello,
I have a Data Flow Source that uses a SQL Command to pull data. In the SQL statement, I used CAST to change all varchar types to Nvarvchar to suit MS Access. I can preview the data from the source. In testing, the SQL statement only pulls about ten records.

I have a Microsoft 2000 Access database table as a destination. Data in each column in the table is required, and all columns have defaults.

I also have a grid data viewer set up. I have the DefaultBufferMaxRows set to 2 so that I can see data going across. When I execute this dataflow, no data is transfered to the Access database table. No data shows up in the dataviewer. There are no errors. The 'Execution Results' tab does not show errors, but indicates that zero rows were transfered. There are no warnings.

How do I begin to isolate the problem? The following is the SQL Statement in the Data Flow Source. Thank you for your help! - cdun2

DECLARE @CategoryTable TABLE
(ColID Int,
ColCategory varchar(60),
ColValue varchar(500)
)
--and fill it
INSERT INTO @CategoryTable
(ColID, ColCategory, ColValue)
SELECT
0,
LEFT(RawCollectionData,CHARINDEX(':',RawCollectionData)),
LTRIM(SUBSTRING(RawCollectionData,CHARINDEX(':',RawCollectionData)+1,255))
FROM Collections_Staging
--Assign an ID to each block of data for each occurance of 'Reason:'
DECLARE @ID int
SET @ID = 1
UPDATE @CategoryTable
SET [ColID] = CASE WHEN ColCategory = 'Reason:' THEN @ID - 1 ELSE @ID END,
@ID = CASE WHEN ColCategory = 'Reason:' THEN @ID + 1 ELSE @ID END
--Then put the data together
SELECT --cast to Nvarchar for MSAccess
a.ColID,
CAST(a.ColValue as Nvarchar(30)) AS OrderID,
COALESCE(CAST(b.ColValue as Nvarchar(30)),'') AS SellerUserID,
COALESCE(CAST(c.ColValue as Nvarchar(100)),'') AS BusinessName,
COALESCE(CAST(d.ColValue as Nvarchar(15)),'') AS BankID,
COALESCE(CAST(e.ColValue as Nvarchar(15)),'') AS AccountID,
COALESCE(CAST(SUBSTRING(f.ColValue,CHARINDEX('$',f.ColValue)+1,500)AS DECIMAL(18,2)),0) AS CollectionAmount,
COALESCE(CAST(g.ColValue as Nvarchar(10)),'') AS TransactionType,
CASE
WHEN h.ColValue LIKE '%Matching Disbursement%' THEN NULL
ELSE CAST(h.ColValue AS SmallDateTime)
END AS DisbursementDate,
--COALESCE(h.ColValue,'') AS DisbursementDate,
CASE
WHEN i.ColValue LIKE '%Matching Disbursements%' THEN NULL
WHEN CAST(LEFT(REVERSE(i.ColValue),4)AS INT) > 1000 THEN CAST(i.ColValue AS SmallDateTime)
WHEN LEFT(REVERSE(i.ColValue),4) = '1000' THEN NULL
END AS ReturnDate,
--COALESCE(i.ColValue,'') AS ReturnDate,
COALESCE(CAST(j.ColValue as Nvarchar(4)),'') AS Code,
COALESCE(CAST(k.ColValue as Nvarchar(255)),'') AS CollectionReason

FROM @CategoryTable a
LEFT JOIN @CategoryTable b ON b.ColID = a.ColID AND b.ColCategory = 'Seller UserId:'
LEFT JOIN @CategoryTable c ON c.ColID = a.ColID AND c.ColCategory = 'Business Name:'
LEFT JOIN @CategoryTable d ON d.ColID = a.ColID AND d.ColCategory = 'Bank ID:'
LEFT JOIN @CategoryTable e ON e.ColID = a.ColID AND e.ColCategory = 'Account ID:'
LEFT JOIN @CategoryTable f ON f.ColID = a.ColID AND f.ColCategory = 'Amount:'
LEFT JOIN @CategoryTable g ON g.ColID = a.ColID AND g.ColCategory = 'Transaction Type:'
LEFT JOIN @CategoryTable h ON h.ColID = a.ColID AND h.ColCategory = 'Disbursement Date:'
LEFT JOIN @CategoryTable i ON i.ColID = a.ColID AND i.ColCategory = 'Return Date:'
LEFT JOIN @CategoryTable j ON j.ColID = a.ColID AND j.ColCategory = 'Code:'
LEFT JOIN @CategoryTable k ON k.ColID = a.ColID AND k.ColCategory = 'Reason:'
WHERE a.ColCategory = 'Order ID:'

View 7 Replies View Related

Bulk Copying Xml Child Node Data

Aug 23, 2006

 
I am trying to bulk copy some XML data into a SQL and am generally doing quite well. The XML data I have been given has a child node called "name" which is the same as in the parent node as shown in the highlight of the XML source below. Now I can retrive the data in the parent node using
bulk.ColumnMappings.Add("name", "Name")
but I cannot get any of the data from the child node "Catagory" or " Catagories". Have you any suggestions on how I can get this data.
<?xml version="1.0" ?>

<products>
<product>
 <ProductId>12345</ProductId>
 <name>Productname</name>
 <description>"This is some description  text"</description>
<Categories>
<Category>
 <name>Category type</name>
 <merchantName>Category subtype</merchantName>
</Category>
</Categories>
<fields />
  </product>
Etc…….
</products>
Many thanks in advance
Simon

View 1 Replies View Related

Data Transfer Wizard - Not Copying Properly

Oct 10, 2006

 Here is the scenerioI am trying to copy a database from a live sql server to  a local server.I wanted to copy the tables, triggers, procedures, functions, usersSo I have "Copy tranfer of objects " in the DTS wizard.But the process fails informing that the users are not there in the local server and fails the process.Now what is my expectation is that why the user logins every thing is not copied to the local sever.Help would be more appreciated. Pretty urgent.  

View 30 Replies View Related

Copying Data From Microsoft Access To SQL Server

Oct 16, 2006

Hello I am developing a web application that will allow users to upload a .mdb file and from that file I need to populate an SQL database. I know the table name of the .mdb file, but I am unclear how to structure my data access layer correctly. How do I pull data from the .mdb file and once I have it how do i populate the SQL database?Any advice would be greatly appreciated.thanks! 

View 1 Replies View Related

Properly Copying Data Of Datatype Image

Dec 12, 2007

I have a column called "Image" in a table that stores all the user information.  Image holds the data for the user's badge photo.  I'm currently working on a project to move some of the data from the users table to more relevant tables.  With the SQL script I wrote to copy the data into the new tables the image data appears to not have been transferred correctly.  I had tried storing the image data into a variable of type varbinary(8000) before inserting it back in.  Is there a certain datatype that must be used to store the data when reading from a column of data type "image" and then inserting it into another column of data type "image" without getting truncation or corruption of the data?

View 1 Replies View Related

Question On Copying Over Overlapping Data From One Database To Another...

Dec 2, 2005

... and preserving the relationships.(Note, this is more of a SQL question than a SQL-related ASP.NET question...)Say I have two databases, D1 and D2, with the same three tables:CompaniesDepartmentsEmployeesWith the standard one-to-many relationships down the line, with eachtable having a PK, IDENTITY field like CompanyID, DepartmentID, andEmployeeID.I have a smattering of data in each of D1 and D2 for these tables withoverlaps in the ID field values. What I want to be able to do is copyover D1's data to D2, preserving the relationships in D1 even thoughthere are ID overlaps in D2. So the tool I'd use would have to besmart enough to check for ID dups in D2 and appropriate change the IDvalues in D1's tables, maintaining the relationships.Is there some built-in SQL tool to do this or do I have to do this myself?Thanks!

View 5 Replies View Related

Issues Copying Data To Linked Server

Oct 24, 2005

I'm having an issue with a job that calls a stored procedure. The SP is fairly complicated, but basically creates a temp table, then inserts the records from the temp table into a table on a linked server (via VPN). The basic premise here is that I'm trying to update a web-accessible server from the production server. The funny thing is that the process works correctly for 4 out of 5 companies (company is the only parameter fed to the SP). The company that fails is by far the largest, but the process has worked in the past.

I'm not strong with all the tools available in SQL Server that might help me figure out what's going wrong. In the SQL Server Agent, it simply tells me that the job failed. If I use Query Analyzer and run the SP in Debug mode (if I'm stating that correctly), I get this error for any company I try it for, even companies that run fine (line 51 is the DELETE line):

Server: Msg 7391, Level 16, State 1, Procedure procStmtDataToReno, Line 51
[Microsoft][ODBC SQL Server Driver][SQL Server]The operation could not be performed because the OLE DB provider 'SQLOLEDB' was unable to begin a distributed transaction.

So I suppose my long-winded question is, how can I determine why this SP fails for the one company? If relevant, the job is simply:

EXEC procStmtDataToReno 'B'

and some snippets of the SP:

CREATE PROCEDURE [dbo].[procStmtDataToReno]

@CoCode as varchar(2)

AS

--various declarations and such

DELETE
FROM [10.1.1.4].OnlineAR.dbo.StatementData
WHERE CompanyID = @CoCode AND (Line1Date < Convert(varchar(10), GETDATE() - 60, 101) OR Line1Date >= Convert(varchar(10), GETDATE() - 5, 101) )

--code to build temp table

INSERT INTO [10.1.1.4].OnlineAR.dbo.StatementData
SELECT * FROM #Statement
GO

TIA

View 3 Replies View Related

SQL Server 2012 :: Copying Data From One Set Of Tables To Another

Mar 26, 2014

1. Take a subset of data from about 100 tables that have multiple references to other tables in this group of 100 from a first DB.
2. Insert the above data into a second DB, a database that already has data in the 100 tables, while maintaining the correct references.

As a general approach, the best way I can think of doing this is as follows:

1. Create mapping tables for every ID that is referenced in a different table (OldID NewID)
2. Insert the old data into the new table and output the OldID and NewID into the mapping table.
3. Use that mapping data to make sure all tables that use those IDs have the new IDs in DB2.

This approach is extremely labor intensive both on initial implementation and would require a fairly substantial amount of work to maintain going forward.

View 7 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved