Monday 29 September 2014

Create a folder with current date



Here i am going to explain, how to create a folder (folder name is current date 'YYYYMMDD') in SSIS using 'File System Task'.

  • Create three variables
    • Folder_Path
    • Folder_Name
    • Full_Path
Give the required path for the variable "Folder_Path", and writhe expression for the variables 'File_Name' and 'Full_Path' (Use the below expressions).

Variable NameData TypeValue/Expression
Folder_PathStringD:\ (Give required path)
Folder_NameStringSUBSTRING((DT_WSTR, 10) (DT_DBDATE) GETDATE(), 1,4)
+SUBSTRING((DT_WSTR, 10) (DT_DBDATE) GETDATE(), 6,2)
+SUBSTRING((DT_WSTR, 10) (DT_DBDATE) GETDATE(), 9,2) 
Full_PathString@[User::Folder_Path]+ @[User::Folder_Name]










  • Take 'File System Task' and edit.
  • Select "Operation" as "Create Directory" from the drop-down list.
  • Set "IsSourcePathVariable" as "True"
  • Select "Full_Path" Variable from the "SourceVariable" Drop-down list.
 
  • Click on "OK" Button and run the package.


Write Expression For a Variable



           In this post i am going to explain, how to write expressions for variables.

Example: I need a string variable. The variable value should be current date, date format is "YYYYMMDD".

  • Create a variable (Sample_Date) with string data type.
 

  •  Select the variable and press "F4", then variable properties will open.
 

  •  Set "EvaluateAsExpression" value as "True".
  • Go to Expressions and write the below mentioned expression for current date.
Expression: 
SUBSTRING((DT_WSTR, 10) (DT_DBDATE) GETDATE(), 1,4)
+SUBSTRING((DT_WSTR, 10) (DT_DBDATE) GETDATE(), 6,2)
+SUBSTRING((DT_WSTR, 10) (DT_DBDATE) GETDATE(), 9,2)


  • Save the SSIS package then we can see the variable value.