user3156193
user3156193

Reputation: 11

I want to update the salary for the employees whose joined last 6 years in sql

I tried this query, but I'm stuck in the where condition. Can anybody help me how to update the salary for the whose joined last 6 years?

Query:

update emp
set sal=sal+3000
where doj=(select doj from emp where doj)

Upvotes: 0

Views: 315

Answers (5)

kord
kord

Reputation: 121

You can use "between" clause

update emp
set sal=sal+3000
where doj between dateadd(year, -6, getdate()) and getdate()

Upvotes: 0

Tejadeep
Tejadeep

Reputation: 1

update emp 
set sal=sal+3000 
where datediff(doj,select getdate(),yy)<=6

Upvotes: -1

Hell Boy
Hell Boy

Reputation: 981

update emp
set sal=sal+3000
where doj=(select doj from abd where datepart(year,doj) between  2009 and 2015)

Upvotes: 0

Mahbubur Rahman Manik
Mahbubur Rahman Manik

Reputation: 5161

Hopefully this will help :)

update emp set sal=sal+3000 where doj>=sysdate-6*365 and doj<sysdate;

Upvotes: 2

Sachu
Sachu

Reputation: 7766

update emp
set sal = sal + 3000
where select datediff(day,doj,Getdate()) / 365.2425 >= 6

Upvotes: 1

Related Questions