I am inserting records into a datatable after insertion , max(sno) lessathan rows I am deleting.
No When record is not inserting means SNO is not changing I need to delete that record immediatly.I have row created time field in the table.
how to delete record when the SNO is not changed?
What I have tried:
declare @Id int
set @Id =(select ISNULL(MAX(SNO),0) + 1 as Sno from dbo.tblInfo)
insert into dbo.tblInfo(SNO,BeaconName,BeaconUUID,MajorValue,MinorValue,RSSI,Status,CreatedDate,DeviceId) values (@Id,@BeaconName,@BeaconUUID,@Majorvalue,@MinorValue,@RSSI,'ACTIVE',getdate(),@DeviceId)
delete from tblInfo where SNO not in (select SNO from dbo.tblBeaconsInfo where CreatedDate in (select max(CreatedDate) from tblBeaconsInfo group by DeviceId))