I have now solved the problem with a function to strip the serial number and a trigger to do the check. I have attached the code for anyones interest in the future. Thanks for all assistance give!FUNCTIONCreate function dbo.StripSerialNo (@MSerialNumber nvarchar(200))RETURNS nvarchar(200)asbegin declare @strNoHyphens varchar(200), @strNoSpaces varchar(200), @strNoZeros varchar(200) set @strNoHyphens = Replace(@MSerialNumber, '-', '') set @strNoSpaces = replace(@strNoHyphens, ' ', '') set @strNoZeros = replace(LTRIM(replace(@strNoSpaces, '0', ' ')), ' ', '0') return(@strNoZeros)end
TRIGGERCREATE trigger check_Serial_No on dbo.Equipment for Insert, updateasdeclare @SNstripped nvarchar(200), @SN nvarchar(200), @MID integer, @SerialNo nvarchar(200), @EID integerselect @SN = MSerialNumber, @MID = ManufacturerID, @EID = EquipmentIDfrom insertedif @SN is not null Begin set @SNstripped = dbo.StripSerialNo(@SN) --if serial number exists already then if exists (select MSerialNumber, ManufacturerID from dbo.Equipment where (dbo.StripSerialNo(MSerialNumber) = @SNstripped) and (ManufacturerID = @MID) and (EquipmentID <> @EID)) begin raiserror ('An Equipment record already exists with that serial number. The record will nno be saved at this time.',16,1) rollback transaction end END