Search
 
SCRIPT & CODE EXAMPLE
 

SQL

sql server get number of working days in a month

DECLARE @StartDate DATE ='2022-06-01',
        @EndDate DATE ='2022-06-30'
;WITH CTE
AS
(
SELECT DATEADD(DD,Number-1,@StartDate) MOnthDates,
       DATENAME(DW,DATEADD(DD,Number-1,@StartDate)) As DayNAmes,
       CASE WHEN DATENAME(DW,DATEADD(DD,Number-1,@StartDate)) IN ('Saturday','Sunday') THEN 0 ELSE 1 END WeekDays
FROM master.dbo.spt_values
WHERE [Type]='P'
AND Number Between 1 AND 10000
)
SELECT COUNT(WeekDays)  AS WeekDaysCount
FROM CTE
WHERE WeekDays<>0
AND MOnthDates Between @StartDate AND DATEADD(DAY,1,@EndDate)
Comment

PREVIOUS NEXT
Code Example
Sql :: how to install mysql workbench in ubuntu 20.04 
Sql :: mysql multiply 
Sql :: min max in sql 
Sql :: inserting values in sql 
Sql :: how to create local postgres database 
Sql :: mysql update LAST_INSERT_ID() 
Sql :: test database for sql 
Sql :: mql4 sleep 
Sql :: find the names of sailors who have reserved at least one boat 
Sql :: import mysql db 
Sql :: sql case sttement with set 
Sql :: oracle sql procedure return value 
Sql :: sql not 
Sql :: right join 
Sql :: sql create table as 
Sql :: sql transaction 
Sql :: mysqlimport 
Sql :: select sql 
Sql :: SQL Greater Than Operator 
Sql :: sequelize postgresql schema 
Sql :: sqllite format 
Sql :: identitye atama yapma SQL 
Sql :: app times 
Sql :: modularity meaning in plsql 
Sql :: psql fetch all rows with null 
Sql :: how to update date in oracle 
Sql :: sql declare variable single line 
Sql :: Get the Domain Name, Page Name and Query Parameter from a URL 
Sql :: mssql get running queries by spid 
Sql :: query to fetch 50% records from the table. 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =