I have table TblLandRiverSegment
RiverSegment CbSegId
EL0_4591_0000 80
EL0_4591_0000 81
XYZ_5570_0017 91
EL1_5570_0001 91
EL1_5570_0002 NULL
EL1_5570_0002 73
I am trying to update with help of self join
UPDATE T
SET T.CbsegId =S.CbsegId
FROM TblLandRiverSegment T
JOIN TblLandRiverSegment S
ON S.RiverSegment = T.RiverSegment
for your ease
CREATE TABLE TestSegment
( RiverSegment Varchar(100) , CbSegId INT )
INSERT INTO TestSegment
VALUES('EL0_4591_0000', 80),
('EL0_4591_0000',81)
UPDATE T
SET T.CbsegId =S.CbsegId
FROM TestSegment t
JOIN TestSegment S
ON S.RiverSegment = T.RiverSegment
SELECT * FROM TestSegment
If you look at the first 2 rows the riversegment are same but cbsegid are different, when i update this update wont work technically as update will not know what record to update ..it runs but will not update technically....so in this situation i need to throw error Raise error more records to update on multiple cbsegid have same landsegment some thing like that ..
Please help me ..
Thanks