Hi guys Need help.
Here is my sample code
Create table tblsource
(
ID INT
,ADate_Source DATETIME
,lid_update INT
);
CREATE TABLE tbldestination
(
ID INT
,Date_Destination_min DATETIME
,Date_Destination_max DATETIME
,Lid int
);
Insert into tblsource (ID,ADate_Source)
SELECT '1','2017-02-02 18:10:00.000'
UNION
SELECT '2','2017-02-02 18:15:00.000'
insert into tbldestination(ID,Date_Destination_min,Date_Destination_max,Lid)
SELECT '10','2017-02-02 17:50:00.000','2017-02-02 18:20:00.000',428117
update tblsource
SET lid_update = D.Lid
from tblsource s
inner join tbldestination d
ON S.ADate_Source BETWEEN D.Date_Destination_min AND D.Date_Destination_max
SELECT * FROM tblsource
SELECT * FROM tbldestination
drop table tblsource
drop table tbldestination
Here is the result I am getting after I ran above code
ID ADate_Source lid_update
1 2017-02-02 18:10:00.000 428117
2 2017-02-02 18:15:00.000 428117
However, I want this
ID ADate_Source lid_update
1 2017-02-02 18:10:00.000 428117
2 2017-02-02 18:15:00.000
I don't want to use the same ID again. Once I use that ID, I don't want to use again.
Above example are my sample code and the sample scenario.
Thank You for your help in advance.