Adding month name to file in ssis

浪子不回头ぞ 提交于 2020-12-12 09:16:36

问题


Is there any expression from which I can directly get the month name in expression builder?

I am supposed to add month name with file name dynamically. I am currently using "DATEPART" function from which i recieved the month number but I want Month name. Can anyone help me?


回答1:


No - unfortunately not. You have two options:

  1. Return the month name from SQL as part of your dataset or
  2. Do a bit of a crazy expression:

(MONTH(yourDate) == 1 ? "January" : MONTH(yourDate) == 2 ? "February" : MONTH(yourDate) == 3 ? "March" : etc etc)




回答2:


SSIS Expressions have a very limited set of functions. If I remember correctly, it offers the functions that were available with VBScript way back when. There are no string formatting functions even in 2016 according to the documentation and people end up concatenating the various parts of a string.

You can use a Script step though to format a date using String.Format and store the result in a variable, as shown in [Using Variables in a Script Task] (https://msdn.microsoft.com/en-us/library/ms135941.aspx) and this SO question, eg:

var targetFolder=Dts.Variables["User::targetFolder"].Value;
var filePrefix=Dts.Variables["User::filePrefix"].Value;
var someDate=Dts.Variables["User::myDate"].Value;

var filePath= = String.Format(CultureInfo.InvariantCulture,"{0}_{1:MMMM}.txt",filePrefix,someDate);
var fullPath=Path.Combine(targetFolder,filePath);

Dts.Variables["User::filePath"].Value=fullPath;

The advantage of a script task is that you can use all of .NET's functions to format values (eg String.Format) and manipulate paths (eg Path.Combine, Path.GetFileNameWithoutExtension etc)



来源:https://stackoverflow.com/questions/38197637/adding-month-name-to-file-in-ssis

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!