Posts

Showing posts with the label C#

SSIS - Standardize date format stored in a text column

Problem: I have trade_date column which looks like this : Trade_date 10-02-2012 1-23-2014 feb-14-2016 1 / 2 / 2012 01 / 02 / 2012 01 / 01 / 12 2014 / 10 / 26 I want to have one unified format after transformation which is MM/dd/yyyy. Does anyone have this problem before or anyone know how to fix this problem? Solution: You need a Script Component to do that, since you are looking to convert multiple date formats. First, you have to create an array of strings that contains all formats needed then you should use  DateTime.ParseExact()  function After adding a Script Component, Make sure you add a New Output Column of type string (Or date if you are looking to convert values into date column), then use the following lines of code within the script: string [] formats = { "dd-MM-yyyy" , "yyyy-MM-dd" , "d-M-yyyy" , "MMM-dd-yyyy" , "dd/MM/yy" , "yyyy/MM/dd" , "dd/MM/yyyy" , "}; Row . outColumn = ...

C# - Extract objects from SQL Command

Problem: How can I extract all objects mentioned in a SQL Command using C#? Solution: It is not easy to extract object names from an SQL command since they may be written in different ways  (with/without schema , databases name included ...) But there are many option to extract objects from an SQL query that you can try: Using Regular expressions, As example: You have to search for the words located after the following keywords: TRUNCATE TABLE FROM UPDATE JOIN The following code is a C# example: Regex regex = new Regex ( @"\bJOIN\s+(?<Retrieve>[a-zA-Z\._\d\[\]]+)\b|\bFROM\s+(?<Retrieve>[a-zA-Z\._\d\[\]]+)\b|\bUPDATE\s+(?<Update>[a-zA-Z\._\d]+)\b|\bINSERT\s+(?:\bINTO\b)?\s+(?<Insert>[a-zA-Z\._\d]+)\b|\bTRUNCATE\s+TABLE\s+(?<Delete>[a-zA-Z\._\d]+)\b|\bDELETE\s+(?:\bFROM\b)?\s+(?<Delete>[a-zA-Z\._\d]+)\b" ); var obj = regex . Matches ( sql ); foreach ( Match m in obj ) { Console . WriteLine ( m . ToStri...

SSAS - Efficient way to process a multidimensional cube

Image
Problem: I am building a multidimensional cube using SSAS, I created the partitions based on a date column, and defined a partition for each day. Source data size is bigger than 2 TB. While deploying and processing the the cube, if an error occurred all processed partitions are not save and their state still unprocessed. After searching for a while I found the  following article  mentioning that: Parallel (Processing option): Used for batch processing. This setting causes Analysis Services to fork off processing tasks to run in parallel inside a single transaction. If there is a failure, the result is a roll-back of all changes. After searching i found an alternative way to process partitions one-by-one from an SSIS package as mentioned in the following article: Create SQL Server Analysis Services Partitions using AMO But the processing time increased more than 400%. Is there is an efficient way to process partitions in parallel without losing all progress wh...