siva nathan

siva nathan

  • 864
  • 819
  • 216.7k

how to avoid existing date below in sql?

Mar 24 2017 8:25 AM
   I'n my sql 2012 im generating a series of current month date like below in grid
 
 this is the query im using to generate a date
; WITH dates(Date) AS
(
SELECT DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0) as Date
UNION ALL
SELECT DATEADD(d,1,[Date])
FROM dates
WHERE DATE < DATEADD(MONTH, DATEDIFF(MONTH, -1, GETDATE()-1), -1)
)
Select * from ( select convert(varchar(max),DATE,105) as [AttDate] from master_table) as tt
 
  date 
2017-03-01
2017-03-02
2017-03-03
2017-03-04
2017-03-05
 upto
 
2017-03-30
im inserting a date in one  sample table like below 
 date
 2017-03-01
 2017-03-03
 
 
once i insert a date in sample table i dont want to generate that date in grid how can i achieve that task
my fina result is 
2017-03-02
2017-03-04
2017-03-05
upto
2017-03-30
 

Answers (8)