DELETE FROM `emp` WHERE DATEDIFF(`year`,`2019-01-01`,emb)>15
I NEED TO HAVE THE employes that spend around here more than 15years and get them off this database or at least this table plz help
DELETE FROM `emp` WHERE DATEDIFF(`year`,`2019-01-01`,emb)>15
I NEED TO HAVE THE employes that spend around here more than 15years and get them off this database or at least this table plz help
You certainly can. Note the syntax - you need the earlier date before the later date:
DATEDIFF ( datepart , startdate , enddate )
And the year keyword doesn't require quotes. You can find specific examples in the documentation here - https://docs.microsoft.com/en-us/sql/t-sql/functions/datediff-transact-sql?view=sql-server-2017
You can test it out by changing the delete to a select and confirming that it is identifying the rows you want to remove:
select * from emp where datediff(year, emb, '2019-01-01') > 15
Once you are sure that it's right, you can change the select * back to a delete
19 People are following this question.