Isolate values in a comma delimited field using SSIS - ssis

I've been working in SSIS trying to parse a multi-valued excel spreadsheet field using VB.Net. My script works by searching for a comma, then using string functions (Left, Right) to whittle down the string until it's null.
Is there an SSIS toolbox function that will do that for me? If so, please tell me :)
Using Visual Studio 2019, Excel 2016.

I personally use c# script component for this.
string textToSplit = Row.[Your Column].Value;
string[] splits = textToSplit.Split(',');
//Now you can work with all sections
foreach(string split in splits)
{
//This is where you do something with each part
}
If the strings are quote wrapped or have commas inside the pieces then you have to use a more complicated splitter utilizing REGEX.

Well, I think I figured it out - it's to use the derived column transformation within the data flow task. With it I can use LEFT and RIGHT functions to parse. I appreciate the help with the C# code - my VB.Net code is very similar. Going to test on Monday!

Related

Advanced mapping of JSON in Azure Data Factory - some guidance requested

I'm trying to map a JSON document (sensor data) into a more meaningful representation using Mapping Dataflows. However, hard time getting this to work and would really appreciate some insight/recommendations on how to solve the following:
The input is
What I would like to end up with is the following:
Any pointers as to how this can be implemented are more than welcome.
This can be accomplished using the Copy activity and then split function in Derived Column transformation in Azure Data Factory.
Use the copy activity to read the JSON file as source and in sink, use SQL database to store the data as table. In Mapping tab, Import the schema and map the JSON records to the corresponding column names. Refer this third-part tutorial for guidance - https://sqlkover.com/dynamically-map-json-to-sql-in-azure-data-factory/
Finally, use the Data Flow activity and choose the SQL table as source now which you have used as sink above.
Select the Derived Column transformation.
Use split function.
Add the column which will take the split values which you want to split as shown below.
Use split(<column_name_to_split>, '_') function to split the column on with _ delimiter. Change <column_name_to_split> to the name of column you cant to split. Refer image below.
Preview the data to check the result.

Write Code in a Spreadsheet Using Visual Basic

I am new to Excel VBA and I am trying to achieve what is displayed in the Result column in the image. I need to develop a code in spreadheet which would create a json based on the occupation of an individual. Please advice how can I fill data in column H (Result) easily using visual basic.
As #ron rosenfeld mentioned you data is inconsistent from row to row. Is there some logic to decide what columns to use? You also don't need VBA to do this. You could use the concatenate function as below:
=CONCATENATE("{""",$A$1,""":""",A2,""",""",$B$1,""":""",B2,"""}")
The output for row two would be:
{"Occupation":"Doctor","FirstName":"Alex"}
If there are conditions you also use the IF function to only show certain columns. If it is more complex I would download the json.bas file from github and generate using that class.

Difficulties with constructing path to desired element?, Excel VBA

I'm new to VBA, trying to learn it. Facing a minor problem in extracting one data point from html.
Below is the html
{ div class="category">Category: Shopping
I just want to extract ( Shopping ) from this but what I'm getting is (Category:Shopping).
I'm using this code
html.querySelector(".category").innerText
Thanks in advance.
I would say the simplest is to use Replace$
data = Replace$(html.querySelector(".category").innerText,"Category:", vbNullString)
You could possibly use split
data = Trim$(Split(html.querySelector(".category").innerText,"Category:")(1))

ssrs url path string manipulation

I have a url string that I'm getting from the DB for a file in my sharepoint server e.g.
http://mysharepointserver.com/abc/def.jpg
and I would like to get the url path e.g. http://mysharepointserver.com/abc removing the file name. Can someone please give me an example on how this can be done in SSRS? I'm using SSRS 2012 but I'm fairly new to SSRS.
Any help greatly appreciated.
Vince.
You could write some custom code on the report. There is a Code property on the report itself where you can write VB functions. One similar to this should do the job.
Function GetPath(ByVal FullPath As String) As String
Return System.IO.Path.GetDirectoryName(FullPath)
End Function
Then in the expression on a Textbox you can call the function.
=Code.GetPath("http://mysharepointserver.com/abc/def.jpg")
For more detailed step by step instructions try http://msdn.microsoft.com/en-us/library/ms156028.aspx

Custom code in Reporting Services report

In Reporting Services I would like to add a parameter that contains data from a custom code block. Ideally, I would be able to run the following code (this is a simple testing example):
Function GetPeriods() As String()
Dim values As System.Collections.ArrayList =
New System.Collections.ArrayList()
For i as integer = 1 to 24
values.Add(i)
Next
Return values.ToArray()
End Function
and put the following in the "Text Field" of the parameter:
=Code.GetPeriods()
However, when I run the report, the parameter I apply this to is disabled and empty. Is there a different technique that should be used? Or am I doing something wrong?
If you're using SQL 2008 Reporting Services then you can have a look at this page which introduces the concept of using custom assemblies.
If you're using SQL 2005 Reporting Services then this link is the one you want.
It's a mostly trivial thing, simply compile your code into a class library and follow the instructions provided to allow your report to reference it.
You are returning an array item (an array of strings) into a text field. Instead, try returning a plain string. That should work. If you would still like to return an array list, you must basically bind it to a list control in your RDL. You can definitely do that with dataset extensions. However, I am not sure if there is any other easy way. Check the proprties of the list control and see if it allows you to directly bind to an array list.
You can create the same stored procedure on SQL Server and load parameter values from that procedure.
To access your members/functions implemented in custom code of SSRS report you should set the access modifier to "Public":
Public Function GetPeriods() As String
...
see article Writing Custom Code in SQL Server Reporting Services
I've been trying to do this same thing, set a simple list of parameter values from report code. None of the links in any of these answers shows how to do this and after quite a bit of digging around I don't think it's even possible. Yes it is possible to get the values from a database query, from a web service, or from a custom assembly, but each of these creates a lot of overhead compared to getting the list from a simple function call like =Code.GetValues(), where the function uses a For loop to create the values.
msvcyc is correct in pointing out that the parameter is expecting a string value, but the function is returning an array. I changed the return type to Array as suggested by prashant sable, but the select list is still grayed out, it does not work. And coldice is correct in saying that the access modifier should be Public.
In my digging around I found an article by James Kovac from 2005 that pointed out why this is not possible. The Parameters class has a get method, but no set method. In the VS 2008 object browser for SSRS 2008 the object name has changed, but it still does not contain a set method (see Microsoft.ReportingServices.Interfaces.IParameter.Name or .Value).
My current workaround is to just hard code the list of values, but if your value list needs to be dynamic then your only choices are database queries, web services, or custom assemblies. I think the easiest workaround of these three is to get the values from the database engine, as suggested by oleksiy.t, as long as you can write a query to return the value list you want. Your list of integers, or my list of time intervals, would both be easy queries to write. Otherwise you will need to use one of the other two workarounds.
I checked your code. The only thing that's wrong is your function returns String(). When I changed your method signature to return Array, it worked fine, in my report.
Change the signature to Function GetPeriods() As Array
Everything I've seen requires parameters and their respective settings to be part of the RDL.
That being said, if you're going to "hardcode" the values, you could create a dataset just for the report, perhaps in XML, or if it needs to be programmatically driven, do it in a web service.