Reputation: 37
I have a table where records for a user are stored
This includes 2 columns applied_date.
,js_id.
now i have to count js_id have applied to number of job this month.
Upvotes: 2
Views: 386
Reputation: 280252
For a specific month (given a date),
DECLARE @date SMALLDATETIME = '20120105'; -- for January, also could use CURRENT_TIMESTAMP
-- the above could also be a stored procedure parameter
SET @date = DATEADD(MONTH, DATEDIFF(MONTH, 0, @date), 0);
SELECT COUNT(js_id)
FROM dbo.[table_name]
WHERE applied_date >= @date
AND applied_date < DATEADD(MONTH, 1, @date);
Upvotes: 2
Reputation: 11377
Select count(js_id) from yourtable WHERE DATEDIFF( m, applied_date, GETDATE() ) = 0
Upvotes: 0
Reputation: 2035
Something like:
SELECT COUNT(js_id), MONTH(applied_date)
FROM table
GROUP BY MONTH(applied_date)
Upvotes: 2