ahmed elbarbary

ahmed elbarbary

  • 636
  • 1.6k
  • 282.1k

How to handle date on temp table when is null or not ?

Jan 25 2020 4:13 AM

How to handle date on temp table when is null or not ?

I work on SQL server 2012 I using format dd/mm/yyyy

I need to handle date on #temp table on both of fromdate or todate .

if i have null on fromdate or todate what i do

if some one write formate date is wrong How i make it as dd/mm/yyyy
  1. create table #temp  
  2. (  
  3. masterId  int,  
  4. fromdate datetime,  
  5. todate   datetime  
  6. )  
  7. insert into #temp values  
  8. (1,'12/01/2017','05/06/2019'),  
  9. (2,'12/02/2018','12/07/2019'),  
  10. (3,null,'12/09/2019')  
  11.   
  12.   
  13. select * from pcn.MasterData M inner join #temp tmp on m.MasterDataID = tmp.masterId  
  14. WHERE (tmp.fromdate is null OR tmp.fromdate >= M.InsertionDate ) AND (tmp.ToDate IS NULL OR tmp.ToDate <=M.InsertionDate)  
 

Answers (3)