(scottish) sql bob blog


Some thoughts of your typical data shepard / data groomer / data dance teacher sort of person.

Why should programmers be more like plumbers, electricians or mechanics

Over the years l have worked with many different people, and observed many people at work.  When working in a mechanical garage l was impressed with the range of tools used by the time served mechanic's.  When a plumber and electrician come to fit a new kitchen l was always was curious about the range to tools to do different jobs.

Today l had a relatively simple task when completing data migration task, which l was doing using SSIS.  Most of the work uses TSQL when possible.  In this case though l was asked convert the a string value from the source for one specific control on one form to Camel Case.  First thought use play to my strengths and use TQL, so quick google, and found this stack overflow posting -> http://stackoverflow.com/questions/5164201/is-there-any-sql-server-built-in-function-to-convert-string-in-camel-case

Ok yes it was possible to use TSQL, the phrase that ran through my mind at that point was "when you have a hammer everything looks like a nail".  Yes l could create the function and call it from the query etc.... 
SSIS is the most wonderful toolbox though (pun intended if you notice it).  One of them is the script task.  Since l only had to convert one control (there is a large number!) why not use some code?  Would that be easier?  Goggling lead to stack overflow posting -> http://stackoverflow.com/questions/1206019/converting-string-to-title-case-in-c-sharp ( This article filled in the gaps for me https://msdn.microsoft.com/en-us/library/system.globalization.textinfo.totitlecase.aspx

My code 
public void Main() 

            string fieldName = (string)Dts.Variables["User::str_Field_ID"].Value; 
            string stringValue = (string)Dts.Variables["User::str_NNLFP_VALUE_TXT"].Value; 
            if (fieldName == "XYZ014") 
               TextInfo textInfo = new CultureInfo("en-GB", false).TextInfo; 
                stringValue = textInfo.ToTitleCase(stringValue); 
                Dts.Variables["User::str_NNLFP_VALUE_TXT"].Value = stringValue.ToString(); 
Dts.TaskResult = (int)ScriptResults.Success; 

Yes it has taken me time and effort to learn C#, that said it's an excellent additional to my toolbox.  Yes l could have done the same in TSQL, it would have taken probably taken longer. Right tool for the right job?  That l am sure is a matter of opinion and or debate.  Speaking personally for this specific project yes l believe so.  It has encouraged me to keep adding to my own personal IT toolbox......