declare @FromDate DATETIME declare @ToDate DATETIME
set
@FromDate = '2015-01-01'
set
@ToDate = '2015-12-31' DECLARE @TOTALCount INT
SET
@FromDate = DATEADD(DAY,-1, @FromDate)
Select
@TOTALCount = DATEDIFF(DD, @FromDate, @ToDate);
WITH d AS (
SELECT
top (@TOTALCount) AllDays = DATEADD(
DAY,
ROW_NUMBER() OVER (
ORDER BY
object_id
),
REPLACE(@FromDate, '-', '')
)
FROM
sys.all_objects
)
select
DATENAME(DW, AllDays),
AllDays
From
d
where
AllDays not in (
select
Cal_Date
from
NseData..Tbl_Holiday
)In this code we will learn how to get all the dates plus days name between two date in sql.