Here is my Sample Data (Below SQL For Create Sample Data)
ID,Fname,Lname,Amount,Visit
1,Smith,D,125,1
2,James,C,145,3
3,Norman,S,121,1
4,Sam,P,111,2
Here is End result Looks like.
ID,Fname,Lname,Amount,Visit
1,Smith,D,125,1
2,James,C,145,3
2,James,C,,3
2,James,C,,3
3,Norman,S,121,1
4,Sam,P,111,2
4,Sam,P,,2
What I want to check Visit column If Visit is more then 1 then create a duplicate row. First row with all Information i.e (4,Sam,P,111,2). However, Second row should be without Amount (4,Sam,P,,2) Because we don't want to calculate the same amount twice.
Please help how I can accomplish this one in SQL or SSIS.
Here is the SQL
Create Table InsertMore
(
ID Int
,Fname VARCHAR(50)
,Lname VARCHAR(50)
,Amount Money
,Visit INT
)
insert into InsertMore
Select 1,'Smith','D',125,1
union
Select 2,'James','C',145,3
union
Select 3,'Norman','S',121,1
union
Select 4,'Sam','P',111,2
Select * from InsertMore