Saturday, October 2, 2021

SSIS Date variables tips

  ---getdate  with HH MM Seconds

(DT_STR, 4, 1252) DATEPART("yy" , GETDATE())
+ "-" + RIGHT("0" + (DT_STR, 2, 1252) DATEPART("mm" , GETDATE()), 2)
+ "-" +  RIGHT("0" + (DT_STR, 2, 1252) DATEPART("dd" , GETDATE()), 2)
+" " +RIGHT("0" + (DT_STR, 2, 1252)DATEPART("hh", GETDATE()), 2) +":"+RIGHT("0" + (DT_STR, 2, 1252)DATEPART("mi",  GETDATE()), 2) +":"+RIGHT("0" + (DT_STR, 2, 1252)DATEPART("ss",  GETDATE()), 2)+":"+RIGHT("0" + (DT_STR, 4, 1252)DATEPART("ms",  GETDATE()), 4)

 
 ---getdate -9 days with HH MM Seconds
(DT_STR, 4, 1252) DATEPART("yy" , GETDATE())
+ "-" + RIGHT("0" + (DT_STR, 2, 1252) DATEPART("mm" , GETDATE()), 2)
+ "-" + RIGHT("0" +(DT_STR, 2, 1252)DATEPART("dd" , DATEADD("Day",-9,GETDATE())), 2)
+" " +RIGHT("0" + (DT_STR, 2, 1252)DATEPART("hh", GETDATE()), 2) +":"+RIGHT("0" + (DT_STR, 2, 1252)DATEPART("mi",  GETDATE()), 2) +":"+RIGHT("0" + (DT_STR, 2, 1252)DATEPART("ss",  GETDATE()), 2)+":"+RIGHT("0" + (DT_STR, 4, 1252)DATEPART("ms",  GETDATE()), 4)



 
 

-----: Todays date
(DT_STR, 4, 1252) DATEPART("yy" , GETDATE())
+ "-" + RIGHT("0" + (DT_STR, 2, 1252) DATEPART("mm" , GETDATE()), 2)
+ "-" +  RIGHT("0" + (DT_STR, 2, 1252) DATEPART("dd" , GETDATE()), 2)


---: minues 1 month and minus 1 day:
(DT_STR, 4, 1252) DATEPART("yy" , GETDATE())
+ "-"  + RIGHT("0" + (DT_STR, 2, 1252) DATEPART("mm" , DATEADD("mm",-1,GETDATE())), 2)
+ "-" +  RIGHT("0" + (DT_STR, 2, 1252)   DATEPART("dd" , DATEADD("Day",-1,GETDATE())), 2)




 



---Last 15 minutes:
(DT_STR, 4, 1252) DATEPART("yy" , GETDATE())
+ "-" + RIGHT("0" + (DT_STR, 2, 1252) DATEPART("mm" , GETDATE()), 2)
+ "-" + RIGHT("0" +(DT_STR, 2, 1252)DATEPART("dd" , DATEADD("Day",-9,GETDATE())), 2)
+" " +RIGHT("0" + (DT_STR, 2, 1252)DATEPART("hh", GETDATE()), 2)  
+":"+RIGHT("0" + (DT_STR, 2, 1252)DATEPART("mi",  DATEADD("mi",-15,GETDATE())), 2)
+":"+RIGHT("0" + (DT_STR, 2, 1252)DATEPART("ss",  GETDATE()), 2)+":"+RIGHT("0" + (DT_STR, 4, 1252)DATEPART("ms",  GETDATE()), 4)

https://blog.sqlauthority.com/2009/06/27/sql-server-fix-error-17892-logon-failed-for-login-due-to-trigger-execution-changed-database-context...