Je pense que cette condition est plus appropriée :
IF EXISTS ( SELECT * --No need to choose columns in an EXISTS
FROM tbl_Example t1
inner join
tbl_Example t2
on
t1.StockCode = t2.StockCode and
t1.Type = t2.Type and
t1.ValidFrom < t2.ValidTo and
t2.ValidFrom < t1.ValidTo and
t1.ID <> t2.ID
where
t1.ID in (select ID from inserted))
BEGIN
RAISERROR ('Date range cant overlap existing date ranges for given StockCode and Type', 16, 1)
ROLLBACK --We're in a trigger, we *must* be in a transaction
END
Il utilise la condition la plus simple pour détecter les chevauchements - un chevauchement existe si les deux lignes commencent avant que l'autre ne se termine.