Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 SSIS and Import/Export (2012)
 Merge Rows in SQL

Author  Topic 

tooba
Posting Yak Master

224 Posts

Posted - 2013-12-23 : 18:25:50
Here is my Test Data, Please any advise would be great appreciated.


CREATE TABLE Table1

(

ID NVARCHAR(50),

FName NVARCHAR(50),

LName NVARCHAR(50),

DOB NVARCHAR(50),

Active bit

)



Create Table Table2

(

ID NVARCHAR(50),

PID NVARCHAR(50),

Phone NVARCHAR(50),

Address NVARCHAR(50)

)

Create TABLE Tbale3

(

PID NVARCHAR(50),

OInfo NVARCHAR(50)

)



--Insert Table1

Insert into Table1 (ID,FNAME,LName,DOB)

VALUES ('1','Smith','Tom','12/12/2011')



Insert into Table1 (ID,FNAME,LName,DOB)

VALUES ('2','Smith','Tom','12/12/2011')



--Insert Table2

Insert into Table2 (ID,PID,PHONE,Address)

VALUES ('1','101','5178896566','Test Ave')



-- Insert Table3

Insert Into Tbale3

VALUES ('101','Active Order')



-- Here is my question....



I am Creating a Front End for this, the user is going to SELECT Witch rows they want to MERGE.

here is the update i need from first table



ID FName LName DOB ISactive

1 Smith Tom 12/12/2011 NULL

2 Smith Tom 12/12/2011 NULL



Let Say user select ID = 1 they wants to merge so I want to update in TABLE1 ISactive = 1 for ID=1

and in TABLE2, update ID = 2, data look like this

ID PID Phone Address

2 101 5178896566 Test Ave


and in TABLE3, UPDATE PID = 101
PID OderInfo
101 Active Order

Please feel free to let me know if my questino is not clear and doesn't make sens. Thanks in advance.
   

- Advertisement -