|
Hi All, Please help me with the below mentioned scenarios-> Table structure-> Data is -> Table A Table B-> Scenarios-> Now I need to dump data from Table B into table A using two ways Scenario 1) I needs to dump all data from Table B into table A at last row of Table A but condition is that the the Eid column of first row of Table B should contain value with Max of Eid column value + 1 of Table A For Ex-> from above data Eid column of table A has max value as '103' so the first record of table B should inserted into table B with Eid column value as 104 and subsequently all records of table B should be inserted in the same way. O/P required -> =========== Scenario 2) I needs to dump all data from Table B into table A at a specific row of Table A but condition is that the the Eid column of first row of Table B should contain value of (+1) the value of Eid column value of Table A at that specific row For Ex-> Suppose I need to dump data into table A at row with Eid column value as as '102' so the first record of table B should inserted into table A with Eid column value as '103' and subsequently all records of table B should be inserted in the same way and after that the other records of table A should be updated acoordingly For above data,If I insert data at row with eid as '102' of Table A all data from table B should be insered after that specific row and after that insert operation ,remaining data from table A like rows that were earlier like eid of '103' should be updated with max of value of eid columns + 1 that was calculated after the insert operation Hope I was able to clarify my query. O/P required-> Table A Immediate response would be much appreciated. Regards, Innovator. Query to recover accidentally deleted data sql,recors,record
(comments are locked)
|
|
Here are two solutions (one per scenario): Solution 1:Insert the data from one table into the other, generating new eid values on the way in (works for SQL 2005 and above). Here I am assuming that eid is the driving value in each table and that the id column has no meaning other than to be a primary key.
Next comes scenario 2:Insert the values from one table into another, between rows in the target table, renumbering eid values that are "pushed down" the target table. This solution runs some changes inside a transaction and rolls the transaction back - you will want to change the rollback into a commit once you are sure that the data is being changed as you want it to.
That should allow you to either add all the data to the end of the table or in between current values. firstly i would like to thank @william for ur precious time and effort! sorry @kev,actually earlier i was not familiar with site's procedure to mark as correct,but later i started to mark my questions as answered! u can se my previous few questions where i have marked them as to helpfull,and surely i have thanked each and every people who commented on my post,also would keep in mind to answer the questions henceforth, by the way thnx u guys for helping me!??
Mar 23 '12 at 12:28 PM
innovator
@innovator thanks for your co-operation. As you can see, accepting the answers is beneficial to your karma score too!
Mar 23 '12 at 12:34 PM
Kev Riley ♦♦
@innovator - no worries, I hope you get your data issues fixed.
Mar 23 '12 at 12:42 PM
WilliamD
ya i got my queries resolved,thnx again!
Mar 23 '12 at 12:45 PM
innovator
@innovator - you've still got 11 questions with un-accepted answers. Hope you can find the time to review these. http://ask.sqlservercentral.com/users/5563/innovator.html Thanks.
Mar 23 '12 at 12:53 PM
Kev Riley ♦♦
(comments are locked)
|


So far you have asked a lot of questions on this forum and have had a large number of answers but have not marked any of them as having helped you. This wont encourage people to keep offering solutions to questions you pose. Would you be able to find some time to review the answers that you have had on other questions and mark appropriate one as helpful by clicking the tick beside them please? It isnt much to ask for all the assistance that is offered across this site.
Thanks