Thursday, October 8, 2015

How to get Month/Day name in SSIS derived column Expression


Simply paste below expression 


For month name use this expression

simply we are extracting month from the getdate() sql function later we are assigning month name to it

(MONTH(getdate()) == 1 ? "Jan" : MONTH(getdate()) == 2 ? "Feb" : MONTH(getdate()) == 3 ? "Mar" : MONTH(getdate()) == 4 ? "Apr" : MONTH(getdate()) == 5 ? "May" : MONTH(getdate()) == 6 ? "Jun" : MONTH(getdate()) == 7 ? "Jul" : MONTH(getdate()) == 8 ? "Aug" : MONTH(getdate()) == 9 ? "Sep" : MONTH(getdate()) == 10 ? "Oct" : MONTH(getdate()) == 11 ? "Nov" : MONTH(getdate()) == 12? "Dec":"")

For day name use this expression

simply we are extracting date from the getdate() sql function later we are assigning day name to it
 
(DATEPART("dw", GETDATE())==1 ? "Sunday" :
DATEPART("dw", GETDATE())==2 ? "Monday" :
DATEPART("dw", GETDATE())==3 ? "Tuesday" :
DATEPART("dw", GETDATE())==4 ? "Wednesday" :
DATEPART("dw", GETDATE())==5 ? "Thursday" :
DATEPART("dw", GETDATE())==6 ? "Friday" :
DATEPART("dw", GETDATE())==7 ? "Saturday" : "") 


In sql server:-

select left(DATENAME(month,getdate()),3) as [month_name]