I have the following code which I am trying to use to check if a value is already stored inside the db.
IF EXISTS ( SELECT * FROM [Clock] WHERE [clockIn] ='12/03/2016' AND UserName = 'ROSE' ) BEGIN RAISERROR('CLOCK IS TRUE NOTHING MORE TO DO',16 ,1) ROLLBACK TRAN END ELSE IF NOT EXISTS ( SELECT * FROM [Clock] WHERE [clockIn] ='12/03/2016' AND UserName = 'ROSE' ) BEGIN INSERT INTO [Clock] ([clockIn], [UserName]) VALUES(GetDate(), 'Rose') END I'm not entirely sure why this is working as it always seems to insert a new row into the db and I am puzzled. I have used the following as an example SQL Server IF NOT EXISTS Usage? and also SQL Server 2008 - IF NOT EXISTS INSERT ELSE UPDATE as reference.
getdatevalue but trying to locate them with constant date filter. Also your date format is not locale-safe. Try '20160312'