How To Copy Detail Records To Another Header

Jun 4, 2004

Im trying to copy details from a specific header as details of a different header (eg. all sales items from invoice #10 copied as sales items of invoice #11).

So far I have two stored procedures:
1) sp_copyDetailsOne
/*Create a recordset of the desired items to be copied*/
CREATE PROCEDURE sp_copyDetailsOne @invoiceIdFrom INT, @outCrsr CURSOR VARYING OUTPUT AS
SELECT itemId, itemPrice, itemDescription, itemQuantity
FROM tblSalesItems
WHERE (invoiceId = @invoiceIdFrom)
OPEN @outCrsr


2) sp_copyDetailsTwo
CREATE PROCEDURE sp_copyDetailsTwo @invoiceIdFrom INT, @invoiceIdTo INT
/*Allocate a cursor variable*/
DECLARE @crsrVar CURSOR

/*Execute sp_copyDetailsOne to instantiate @crsrVar*/
EXEC sp_copyDetailsOne @invoiceIdFrom, @outCrsr = @crsrVar OUTPUT

/*Loop through the recordset and insert a new record using the new invoiceId*/
FETCH NEXT FROM @crsrVar
WHILE @@FETCH_STATUS = 0
BEGIN

/*Run the insert here*/
INSERT INTO tblSalesItems
(invoiceId, itemId, itemPrice, itemDescription, itemQuantity)
VALUES (@invoiceIdTo , 5, $25.00, N'Black T-Shirt', 30)

/*Fetch next record from cursor*/
FETCH NEXT FROM @crsrVar
END

CLOSE @crsrVar
DEALLOCATE @crsrVar


My question comes on the Insert of sp_copyDetailsTwo, as you can see the values are hard coded and I want them pulled from the cursor. However I don't know how to do this - do I need varables or can I access the cursor values directly in my VALUES clause? Or is this whole approach needing overhauled. Any advice is welcome.

Thanks

View 2 Replies


ADVERTISEMENT

Header And Detail Records From DTS

Apr 16, 2004

I am creating a DTS package to export a text file. My question is: does anyone have any ideas on how for one read of the tables I can produce 2 lines of output. Here is how the file layout needs to be...

HEADER
DETAIL
HEADER
DETAIL
HEADER
DETAIL

I am a little confused about how I can stagger header and detail using the same data.

I appreciate any help you can give. Hopefully my explanation of the problem is understandable.

Thanks, Val

View 2 Replies View Related

T-SQL (SS2K8) :: Copy Master Record And Its Detail Records

Aug 26, 2014

I have been asked to give the users the ability to copy a set of records within the database. The current setup is

Master Table: JSA1
JSAID: (PK, int, not null)
JOBTITLE(nvarchar(200), null)
PlantNumber(int, not null)

Detail Table: tblSteps
STEPID (PK, int, not null)
JSAID (FK, int, not null)
StepNo (int, null)
BasicSteps (nvarchar(200), null)
DBPhoto(varbinary(max), null)

The plant number field is a location based field that the application uses to filter/select data on for the end users. What they want to be able to do is to select a record, select another location from a dropdown list and then click a button that duplicates the master record and the detail records to the new location.

I am thinking that a stored procedure passing the JSAID and new Location number to do it, I am just not sure how to get the new ID when I go to copy the detail records.

View 4 Replies View Related

Detail Record Header

Mar 29, 2007

Hi,

I'm new to SSRS. I was just wondering how do I make the header for a detail record appear once per grouping rather than once per detail record?



Thanks.

View 1 Replies View Related

SSIS Header And Detail To A File

Feb 19, 2008

Hi Anyone

How to export a header and details data from two different table and export it in the below format ?

RecordCount = 129 ------------> Header
001|Manager|2399.00|12 ------------> Detail Lines
002|Technican|1800.00|15
003|Mechanic|1500.00|18
.......
Total Amount = 180000.00 ------------> Footer Line

I want to use the SSIS to do this job can anyone explain step by step.

Thanks,
Madhu

View 3 Replies View Related

Select With Header And Detail For Each Record In View

Sep 16, 2014

I have a flat file I need to generate, wanted to create my file from a SQL view.

Is there a way to have a Header and Detail Record for each Record in my view?

Fields would be:

Line no type period ref amt date Inv_no
0 M 1 3/3/2014
1 M Pay inv: 400.00 12345

where 0 is the header and 1 is the detail. Only certain fields will be in the header and others in the detail.

View 1 Replies View Related

How To Create A Constraint On A Header And Detail Tables?

Feb 5, 2008



Hello,

I have a header and detail table. I want to create a constraint on the detail table, based on a value it's linked to in the header table. If the bit is checked in header then a unique value is required , if it's not checked then a NULL value is acceptable.

Many thanks in advance.

View 3 Replies View Related

(Revised)Database Design Question, Header With Two Detail.. Pls Help

Jul 20, 2005

Hi All,There is some additional info I forget on this same topic I just posted.I have a database design question, pls give me some help..I want to define tables for salesman's sales target commission . Thecommission could be given per EITHER sales amount of : Group of Products ORGroup of Brand. e.g : the data example :For one salesman_A :product_1, product_2, product_3 etc.. => sales = $100 - $200 =>commission = 5%product_1, product_2, product_3 etc.. => sales = $201 - $400 =>commission = 10%Brand_A, Brand_B, Brand_C .. etc => sales = $100 - $200 =>commission = 2.5%Brand_A, Brand_B, Brand_C .. etc => sales = $201 - $400 =>commission = 5%Below is my table design, is this a good design or something is wrong here ?Thank you for your help.CREATE TABLE Sales_Commission_Header (Sales_ID Char(4) ,Sales_Commission_Group Char(4),Note Varchar(30),Constraint Sales_Commission_Header_PK Primary Key(Sales_ID,Sales_Commission_Group))Alter Table Sales_Commission_Header Add ConstraintFK_Sales_Commission_Header Foreign Key (Sales_Commission_Group)References Commission_Group_Header(Sales_Commission_Group)CREATE TABLE Sales_Commission_Detail (Sales_ID Char(4) ,Sales_Commission_Group Char(4),Sales_From Decimal(12,2) ,Sales_To Decimal(12,2) ,Commission Decimal(5,2),Constraint Sales_Commission_Detail_PK Primary Key(Sales_ID,Sales_Commission_Group, Sales_From, Sales_To))Alter Table Sales_Commission_Detail Add Constraint FK_Sales_CommissionForeign Key (Sales_ID, Sales_Commission_Group) ReferencesSales_Commission_Header(Sales_ID, Sales_Commission_Group)--------------------------------------------** ALTERNATIVE _1 :CREATE TABLE Commission_Group_Header (Sales_Commission_Group Char(4) Primary Key,Note Varchar(30))CREATE TABLE Commission_Group_Detail_Product (Sales_Commission_Group Char(4),Product_ID VarChar(10), -- This product_ID will be FKreference to master productConstraint Commission_Group_Detail_Product_PK PrimaryKey(Sales_Commission_Group, Product_ID))Alter Table Commission_Group_Detail_Product Add ConstraintFK_Commission_Group_Detail_Product Foreign Key (Sales_Commission_Group)References Commission_Group_Header(Sales_Commission_Group)CREATE TABLE Commission_Group_Detail_Brand (Sales_Commission_Group Char(4),Brand_ID VarChar(10), -- This brand_ID will be FKreference to master brandConstraint Commission_Group_Detail_Brand_PK PrimaryKey(Sales_Commission_Group, Brand_ID))Alter Table Commission_Group_Detail_Brand Add ConstraintFK_Commission_Group_Detail_Brans Foreign Key (Sales_Commission_Group)References Commission_Group_Header(Sales_Commission_Group)** ALTERNATIVE _2 :CREATE TABLE Commission_Group_Header (Sales_Commission_Group Char(4),Group_Type Char(1), -- 'B': Brand Group 'P': Product GroupNote Varchar(30),Constraint Commission_Group_Header_PK Primary Key(Sales_Commission_Group,Group_Type))CREATE TABLE Commission_Group_Detail (Sales_Commission_Group Char(4),Group_Type Char(1), -- 'B': Brand Group 'P': Product GroupProduct_Brand_ID VarChar(10),Constraint Commission_Group_Detail_PK Primary Key(Sales_Commission_Group,Group_Type, Product_Brand_ID))Alter Table Commission_Group_Detail Add ConstraintFK_Commission_Group_Detail Foreign Key (Sales_Commission_Group)References Commission_Group_Header(Sales_Commission_Group, Group_Type)The PROBLEM here is : with Product_Brand_ID , I CAN NOT make foreign keyinto both Master Product and Master Brand.So which one is better design ?split the Commission_Group_Detail into Two tables, product and brand , andmake the FOREIGN KEYto master product and master brand (previous mail)ORcombile Commission_Group_Detail for Product and Brand into one table likeaboveand NOT make any FK to master Product or Brand ?Thank you for your help,Tristant

View 1 Replies View Related

Should Be Simple - FLAT FILE - HEADER / DETAIL LINES

Feb 21, 2007

I can't believe it's been a few days and I can't figure this out. We have a flat file (purchaseOrder.txt) that has header and detail lines. It gets dropped in a folder. I need to pick it up and insert it into normalized tables and/or transform it into another file structure or .NET class.

10001,2005/01/01,some more data
SOME PRODUCT 1, 10
SOME PRODUCT 2, 5

Can somebody place give me some guidance on how to do this in SSIS?

View 2 Replies View Related

Transform Header And Detail Flat File Into One Table

Sep 13, 2007

I have a flat file with header and detail information, it is actually employee punch card data. I need to parse the header line which contains the Employee ID and don't save it to a table just save the value. Then with the detail line, parse the different data elements and save them along with the employee ID to one table. Then continue until the next header line is read.


The file looks something like this:

FINNEY,RONNIE 0001005420
Mon 09/03 700a HOL 8.00
Tue 09/04 630a*E 326p 8.50 8.50
Wed 09/05 645a 330p 8.00 16.50
Thu 09/06 639a 2.40 18.90
HALL,MARK 0001005601
Mon 09/03 700a HOL 8.00
Tue 09/04 608a*E 257p 8.40 8.40
Wed 09/05 601a*E 259p 8.50 16.90
Thu 09/06 606a*E 3.30 20.20
JONES,WILLA JEAN 0001005702
Mon 09/03 700a HOL 8.00
Tue 09/04 556a*E 326p 9.10 9.10
Wed 09/05 600a*E 328p 9.00 18.10
Thu 09/06 554a*E 3.50 21.60

So I think I need a data flow transformation object that let's me save the Employee ID into a variable available when the next record is read. What type of transformation would be best?

View 1 Replies View Related

Reporting Services :: Move Detail Row Under Group Header

Nov 23, 2015

I have a report with two groups and a detail row (subtotals & totals to follow).  When I add the child (detail row) it pushes out to the right of the parent column. Is there any way to start the detail row all the way back to the left hand side of the page? I lose a lot or real estate with the group descriptions.

View 5 Replies View Related

Combine Data And Split Into Separate Txt Files For Each Header/detail Row Groupings

Mar 16, 2006

I€™ve created with the help of some great people an SSIS 2005 package which does the follow so far:
 
1)       Takes an incoming txt file.  Example txt file: http://www.webfound.net/split.txt    
 
The txt file going from top to bottom is sort of grouped like this
     Header Row (designated by €˜HD€™)
          Corresponding Detail Rows for the Header Row
           €¦..
     Next Header Row
          Corresponding Detail Rows
 
     €¦and so on  
 
       http://www.webfound.net/rows.jpg
 
2)       Header Rows are split into one table, Maintenance Detail Rows into another, and Payment Detail Rows into a third table.  A uniqueID has been created for each header and it€™s related detail rows to form a PK/FK relationship as there was non prior to the import, only the relation was in order of header / related rows below it when we first started.  The reason I split this out is so I can massage it later with stored proc filters, whatever€¦
 
Now I€™m trying to somehow bring back the data in those table together like it was initially using a query so that I can cut out each of the Header / Detail Row sections into their own txt file.  So, if you look at the original txt file, each new header and it€™s related detail rows (example of a cut piece would be http://www.webfound.net/rows.jpg) need to be cut out and put into their own separate txt file. 
 
This is where I€™m stuck.  How to create a query to combine it all back into an OLE DB Souce component, then somehow read that souce and split out the sections into their own individual txt files.
 
The filenames of the txt files will vary and be based on one of the column values already in the header table.
 
Here is a print screen of my package so far:
 
http://www.webfound.net/tasks.jpg
 
http://www.webfound.net/Import_MaintenanceFile_Task_components.jpg
 
http://www.webfound.net/DataFlow_Task_components.jpg
 
Let me know if you need more info.  Examples of the actual data in the tables are here:
 
http://www.webfound.net/mnt_headerRows.txt
http://www.webfound.net/mnt_MaintenanceRows.txt
http://www.webfound.net/mnt_PaymentRows.txt
 
Here's a print screen of the table schema:
http://www.webfound.net/schema.jpg

View 17 Replies View Related

Integration Services :: Insert Data Into Header And Detail Table From XML Through SSIS Package

Jun 2, 2015

I need to insert data into Header & Detail table. As shown in the below xml,

RecordID is identity-column and incremented by 1, after new record is saved into Header table. Need to assign the same recordID for the detail also.

Expecting output should be like as shown below:

How can we accomplish this requirement.

View 8 Replies View Related

Reporting Services :: Possible To Merge Group Header Cells Used As Toggles To Expand / Contract Detail?

Sep 5, 2015

I have a report with 3 groups, and a toggle on the first cell in the group header, and group totals on that line also. So it renders as:

- Group 1 G1Total G1Total G1Total
- Group 2 G2Total G2Total G2Total
- Group 3 G3Total G3Total G3Total
Detail DAmt DAmt DAmt

I would like to save some space and render more like

- Group 1 G1Total G1Total G1Total
- Group 2 G2Total G2Total G2Total
- Group 3 G3Total G3Total G3Total
Detail DAmt DAmt DAmt

I haven't been able to find a way to have the first group cells overlap each other. Is there a way to do that and am I missing something obvious?

View 4 Replies View Related

Any Way To Show A Group Detail Header Row Once For Each Group In A Table?

Nov 21, 2007

I have a need to show a row inside a table group to simulate a header row for the data rows inside the group. The table will not have a real header or footer. Thanks for the help.

View 1 Replies View Related

Combining Detail Records From Different Tables

Sep 22, 2005

Following is a stored procedure that currently runs on the system (compacted version). I need to combine this data with data from another Table .. tblAdjustments. The schema for this table is fairly close to tblShipmentDet.

tblShipmentHdr --> tblShipmentDet (Key = ShipmentID)
tblAdjustments --> standalone

Result: combine tblShipmentHdr + attached tblShipmentDet records with
tblAdjustments records.

Would the best approach be to use a UNION SELECT?

@XToDate datetime = '7/31/2005' ,@XBegDate datetime = '7/1/2005'
AS
SELECT
SHPH.ProductID,
SHPH.ReceivedDate,
SHPH.ShipmentNo,
SHPD.Vendor,
SHPD.Quantity,
QRecvdDate = CASE WHEN SHPH.ReceivedDate < convert(varchar(40),@XBegDate,121)
THEN NULL ELSE SHPH.ReceivedDate
END,
QShipQty = CASE WHEN SHPD.TransCd = 'F'
THEN NULL
WHEN SHPH.ReceivedDate < convert(varchar(40),@XBegDate,121)
THEN NULL
ELSE SHPH.ShippingQty
END,
PROD.ProductName,
QOpenAccrual = CASE WHEN MEND.OpeningAccrual is Null
THEN 0 ELSE MEND.OpeningAccrual
END
FROM dbo.tblShipmentHdr SHPH
LEFT OUTER JOIN dbo.tblProducts as PROD ON Left(SHPH.ProductID,7) = Left(PROD.ProductID,7)
LEFT OUTER JOIN dbo.tblShipmentDet as SHPD ON SHPH.ShipmentID = SHPD.ShipmentID
LEFT OUTER JOIN dbo.tblMonthend as MEND ON SHPH.ProductID = MEND.ProductID And MEND.MEPeriod = convert(varchar(40),@XBegDate,121)
WHERE ((SHPH.ReceivedDate >= '7/1/2005' AND SHPH.ReceivedDate <= '7/31/2005') OR (SHPD.DatePaid >= '7/1/2005' AND SHPD.DatePaid <= '7/31/2005'))

View 1 Replies View Related

Export Master-Detail Records

Nov 30, 2007

I need to export data to a text file in the following format:

Master Record
Detail Record Detail Record
Detail Record
Master Record
Detail Record
...

Example would be:

Master Record Format:
----------------------------------------------------------------------
RecordType|FirstName|LastName

Detail Record Format:
----------------------------------------------------------------------
RecordType|Order#|OrderedItem

Sample Data:

M|Micheal|Smith
D|123|1-123-1
D|123|1-123-2
M|John|Smith
D|142|1-444-1
D|142|1-444-3

Could someone direct me how I can acomlish this task using SSIS?

Thanks -

View 8 Replies View Related

Transaction Processing Detail Records

Apr 30, 2007

Hello,



I am fairly new to SQL Server 2005 and was curious if this was possible.



In my VB applications I always used Begin Transaction, Commit and Rollback to process records. I just found out that I can perform the same functionality in a stored procedure.



So the question is, if I have an order record and four line item records is there anyway to pass all that to the stored procedure as a unit. I can pass the order record as individual parameters but it is the four (or however many) detail records that is the reason for my question. How can I pass the detail records at one time? Can I pass these as an array or a dataset or something else or am I just out of luck? SQL Server 2005 has impressed me a few times already with what you can do and I am really hoping this can be accomplished also.



Cheers,

Richard

View 3 Replies View Related

SQL Server 2012 :: Combining Master And Detail Records In New Table

Sep 4, 2014

CREATE TABLE DHS(CUSTOMERNBR VARCHAR(20), CONTRACT VARCHAR(20), SUBCONTRACT VARCHAR(20) , STARTDATE DATETIME, ENDDATE DATETIME, EFLAG VARCHAR(20), HFLAG VARCHAR(20))

The data which will be going into this table is from two table which have a 1 to many relationship:

Here is the 1 side and data:

CREATE TABLE CUSTOMERS(
CUSTOMERNBR VARCHAR(20),
CONTRACT VARCHAR(20),
SUBCONTRACT VARCHAR(20),
STARTDATE DATETIME,
ENDDATE DATETIME DEFAULT '12/31/2099')

[Code] ....

Here is the Many side and data:

CREATE TABLE FLAGS(CUSTOMERNBR VARCHAR(20), FLAGCODE VARCHAR(20), STARTDATE DATETIME, ENDDATE DATETIME DEFAULT '12/31/2099')
INSERT INTO FLAGS(CUSTOMERNBR, FLAGCODE, STARTDATE, ENDDATE) VALUES('10001000101', 'H', '02/01/2014', '03/31/2014')

[Code] ....

The CUSTOMERS table holds the record date span into which the FLAGS table records have to "fit". In no case will the date spans from the FLAGS table fall outside the STARTDATE - ENDDATE span in the CUSTOMERS table for any CUSTOMERNBR. Here is an example of the final expected output in the DHS table from combining records in the CUSTOMERS and FLAGS tables:

CUSTOMERNBRCONTRACTSUBCONTRACTSTARTDATEENDDATEEFLAGHFLAG
10001000101A910400801/01/201401/31/2014
10001000101A910400802/01/201403/21/2014H
10001000101A910400804/01/201404/30/2014
10001000101A910400805/01/201405/31/2014H
10001000101A910400806/01/201412/31/2099E
10001000102A555500101/01/201403/31/2014E
10001000102A555500104/01/201404/30/2014EH
10001000102A555500105/01/201406/30/2014E
10001000102A555500107/01/201412/31/2099
10001000103A666600401/01/201410/01/2014

View 1 Replies View Related

Bulk Copy Procedure (BCP) With A Header Row

May 4, 2000

Hi, I am have a text file that contain row header. I want to export this text file into pub database to the author table. I usually use this code:
Exec master..xp_cmdshell "bcp pubs..authors in d:dataauthors.txt /c /Snameofserver /Usa /Ppassword"

from sql analyser window. it the text file does not have a header, I am able to export the data, but if the text file Does have a header, I got an error, I know that I can open the text file and delete the header then run the bcp process. But I do not want to do so, IS there a code that I can add to the bcp code above to accept the header row and have a successful bcp procedure. thanks

View 3 Replies View Related

Selecting Detail Based On A Sum Of The Detail Lines

Sep 14, 2007

I am listing detail transaction lines in a table sorted by account and order number.
the problem is that I only want to see the detail if the sum of a value field is zero for all the transactions in an order otherwise ignore the detail for that order.

I was trying Group by and Having but this doesn't seem to do what I need.

Being relatively new to Reporting services, any nudge in the right direction would be useful.

View 4 Replies View Related

Aha! Multiple Header Records

May 30, 2007

I discovered wherein lies our troubles. Our input file has a header record, followed by several detail records... and then, at some point, another header record, followed by more detail records.

Apparently, SSIS doesn't like this set up and so we're having to rewrite everything in C#.

I have two questions:

1 - How hard would it be for SSIS to split the input file into several input files, breaking at every header record to start a new file?
2 - Is this really something that SSIS has a problem with? Has anyone ever had to deal with/work around this?

Thanks!

Jim Work

View 7 Replies View Related

Is There A Way To Ignore 2 Header Records?

Mar 9, 2008

I want to bulkcopy a pipe delimited text file that has two header records to SQL Server using ADO / C#. The first record contains the datetime the file was recreated and the second record contains the column definitions, both records start with a # character (see below).

# May 15, 2008 12:12:12345
# col1|col2|col3
col1rec1data|col2rec1data|col3rec1data
col1rec2data|col2rec2data|col3rec2data

Is there a way to ignore the two header records when building the select statement for the text file or in the schema.ini?



View 4 Replies View Related

Subreport Header Which Contains No Records, Is Added To The CSV Output

Apr 9, 2008



Hi All,

I've got a main report with five subreports. Based on a value of a parameter in the main report one the subreports is filled with data, all the other subreports will have no records. When the report is displayed in on the reportserver it is working fine, bit when I export the data to a CVS format, also the element names of the subreports are added to the CSV Output.

When i change the value of Data Output of the subreport item in the main report to Auto it doesn't export the records of the filled subreport.

How can I disable the export of the dataelement names in the CSV export?

Hope you can help

Thanks,

Eric

View 2 Replies View Related

SQL Master/Detail (Master Query Based On Detail Values)

Mar 25, 2008



Hello,

I'm new to SQL and need help with a query. Not sure if this is the right place.

I have 2 tables, one MASTER and one DETAIL.

The MASTER table has a masterID, name and the DETAIL table has a detailID, masterID, and value columns.

I want to return a populated MASTER table with entries based on the DETAIL.value.

SELECT MASTER.*
FROM MASTER
WHERE DETAIL.value > 3

This is a simplified version of my problem. I can't figure out how to set the relationship between MASTER.masterID and DETAIL.masterID. If I do an INNER JOIN, the number of results are based on the number of DETAIL entries. I only want one entry per MASTER entry.

Hope this makes sense.

How can I do this?

GrkEngineer

View 9 Replies View Related

Copy Records

Aug 28, 2004

I have 1 table. In that table there are thousands of records. I have an ID that is autonumbered for a unique id.

What i need to do is at any given time select as many records from that table that have a certain Forein Key in it. Take all those records and copy them back into the same table but at that time i need to change some of the values including the Forien Key and the name.

Is there a bulk way to do this without having to loop? If so can you show me.

If not can someone show me the best way to get all the records and copy them back into its own talbe with a new Forien Key and Name.

View 2 Replies View Related

SQL Backup/Copy Records

Aug 31, 2001

Hi i am looking for some advice about sql databases and wondering if anybody can help me.

First the Background.

I am in the process of writing a payroll program that uses SQL as a data store. However rather then creating individual databases for each payroll that can be ran on the system i have created a core payroll table that generates a unique id for each payroll and then reference that thoughtout the system.

Now The Problem

The problem I now have is when I work out the final pay for the employees I want to make a quick copy of the various records just in case I need to undo the net pay calculations for adjustments to the data, it is effectively rolling back the transactions to the database but I want to be able to keep them till I decide that everything is correct.

I cant take a snapshot of the entrie database because the payrolls stored within may be in all sorts of states.

I need to keep the records for just the payroll I'm working on.

Any Ideas or Solutions !!!!!


Thanks

EJ Gibbons
"Where poets speak there hearts, then bleed for it" - U2

View 1 Replies View Related

How Copy Records From 1 Table To Another

May 24, 2008

I have 2 tables.
TABLE 1: AttachmentTypeDefaults (fields: DefaultId (pk), AttachmentType)
TABLE 2: AttachmentType (fields: AttachmentTypeId (pk), CompanyId, AttachmentType)

The @CompanyId variable has to be the IDENTITY of a new record that was just INSERTed into another table just before (in this new SP.)

What I want to do is loop thru the AttachmentTypeDefaults table and INSERT every record into the AttachmentType table and use the @CompanyId for every new record. (AttachmentTypeId will create itself.)

How would I do this?

Sounds easy but I am new.

I would like it to be compatible with SQL Server 2000 also.

I tried a query like this, but I don't think I'm close...
declare @MyNewIdentity int
SET @MyNewIdentity = SCOPE_IDENTITY()

-- Now INSERT default attachments
INSERT INTO AttachmentType(CompanyId, AttachmentType)
VALUES(
SELECT @MyNewIdentity AS CompanyId, AttachmentType
FROM AttachmentTypeDefaults)

View 6 Replies View Related

1.6 Billion Records To Copy

Mar 20, 2008



HELP. I've inherited some less-than-stellar dessign.

I have a table:
tbMD

ObjectID uniqueidentifier not null
Tag nvarchar(50) not null
Data nvarchar(400) not null

This table has 1.6Billion records and has filled up the drive (nearlly 1 TB in the DB, with about 600GB in this one table).

I need to move this table to another drive with ZERO down time.

I have created a new filegroup on a second drive array and created a new table (tbMD_TEMP) and my thought was to copy all the data from tbMD into tbMD_Temp then drop tbMD, and rename tbMD_Temp.

So, anyone have any great ideas on how to get this done very quickly?

View 5 Replies View Related

How To Copy Good Records And Identify Bad Ones

Sep 24, 2012

In a job of migrating from an old database to a new one (with other structure, other server, other version) i'm copying from the source old tables and inserting into the new destination tables. The problem is that some records have inconsistencies (of any kind) and thus are not inserted due to foreign key, not null, etc validation. When a problem occurs none record is copied! and there is my question: How can i perform the copy in wich it copies the good records (without inconsistencies) and leave aside the bad records. I also want to know wich were not copied and better if in the copy process those were put in a temp table or exported to excel for further analisys o its data.

I'm using this model of "migration":

BEGIN TRY

INSERT INTO DESTINTATION_TABLE (
col_d1,
col_d2,
col-d3,
...)

SELECT
col_s1,
dbo.some_function(col_s2),
col_s3 * 100,
...
FROM SOURCE_TABLE join <other_table> ... where <some filters>

END TRY

BEGIN CATCH
print ERROR_MESSAGE()
END CATCH

(for now, with try/catch I've only get to know the error occurred, if some)

View 5 Replies View Related

Copy Parent-child Records With Different IDs?

Dec 11, 2013

I have a parts table which has partid (GUID) column and parentpartId (GUID) column. Need to copy the records to the same table with new GUIDs for partids. How to do that? cursor or temp tables?

View 5 Replies View Related

Copy Records, Limit Characters?

Jul 20, 2006

How could I go about doing the following:

I have a column with lets say

AHA1
AHA2
AHA3
AHE1
AHE2
ARL1
ARL2

How could I make a column next to it that is basically the same but cuts off anything after the third letter? So this new column would look like:

AHA
AHA
AHA
AHE
AHE
ARL
ARL

Thanks!

View 4 Replies View Related

How To Copy Distinct Records From One Table To Another Using SQL 2005

Oct 24, 2007

I have a table on an offline database having let say 2000 rows and same table on an online database with let say 3000 rows. Now I want to copy just those records (1000) from online database that are not in the offline database table. Also, both tables have same name, same schema etc.

View 3 Replies View Related







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