Safwan
Safwan

Reputation: 85

Filter Data by Date

I have question to ask. Currently, I'm developing a payslip application. However, I stuck at 1 part of the process. I'm managed to display salary but I need to filter certain date in order for the salary to be display.

For example, for this September, the company already key in the salary on 26th Sep but user can only see it start from 28th Sep and above. So, basically, the program can show previous month payslip except for September unless user start see it on 28th Sep.

Current Output :

EMPLOYEEID  MONTH   YEAR    SALARY
E001           7    2017    2000
E001           8    2017    2000
E001           9    2017    2000
E002           7    2017    2100
E002           8    2017    2100
E002           9    2017    2100

Expectation output:

EMPLOYEEID  MONTH   YEAR    SALARY
E001           7    2017    2000
E001           8    2017    2000
E002           7    2017    2100
E002           8    2017    2100

Current Query Progress :

SELECT       EMPLOYEEID, MONTH, YEAR, SALARY
FROM           DBO.Salary 
WHERE         day(getdate())>=28

Upvotes: 0

Views: 68

Answers (1)

JohnHC
JohnHC

Reputation: 11195

Today is 2017-09-29, do Sep should appear. Add the OR for when it's less than 28th

select *
from dbo.Salary s1
where day(getdate())>=28
or month(getdate()) > s1.Month

Upvotes: 1

Related Questions