I'm having an issue and I don't know if this is possible to do.
I have a simple SQL task.
SELECT Name, email FROM table_name
Using a result set, I'm trying to pass it to a variable and use it on a email task with a foreach loop but i having no luck getting this to work. If I do just one column, it works fine. My issue is multiple columns.
Thanks for the help in advance.
I figured out my own question. I will add it here in case someone else have the same issue.
On the SQL query the first column should be your key result. for example mine was the email.
In the SQL Task under General, set Resultset to "Full Result rest"
In the SQL Task under Result Set, set variable with "0" as result name, create a variable as "Object" data type for the email column and click ok to save and exit. Example: email_Ob
By going to the variable window, create more variable for the other columns as Object and since I'm using this for email task I need to convert from Object to String, so I need to create another variable as string for each one
Example:
**Variable Name** **Datatype**
email_Ob Object
Name_Ob Object
email_St String
Name_St String
Foreach Loop task Under Collection change the following:
Enumerator: Foreach ADO Enomator
ADO object Source variable: Select the key variable (email_Ob)
Select Rows in the first table
Foreach Loop task under Variable Mappings add the variable with String data type the same order as on your SQL query. Click OK to save and exit.
Now you can add the Email Task inside Foreach Loop and use those String variable as part of the email or you can use it for any other task.
Hope this help and if you have any questions feel free to ask. Doing this way, I was able to add more columns as need it.
Related
I have a url: https://api.xero.com/api.xro/2.0/Reports/ProfitAndLoss?fromDate=2019-06-01&toDate=2019-06-30 which I will use after to call Xero's API.. I need to change fromDate and toDate dynamically. I thought to use https://api.xero.com/api.xro/2.0/Reports/ProfitAndLoss?fromDate=${start}&toDate=${end}. Then, add 'Data grid' with dates to be replaced in the string. But then, I tried to 'Set variables'/'Get variables' but I keep on getting the error 'Only 1 input row was expected to set the variables and at least 2 were received.' What am I doing wrong?
Current transformation:
Transformation:
Sub-job:
Final transformation:
In the set variable you can only set one row. but if you want to pass multiple rows then I suggest you to use job. In job first transformation use Data Grid and then copy rows to result. then create one more sub job. For setting variable use transformation. Make sure execute at every input row is checked. this should be your subjob Structure
I have a subform with user input (text box), that can reach more than 255 chars and can have special characters. As I cannot assign it as a parameter to a vba query definition (only 255 characters will work), I thought about directly referencing the text box:
Insert into ...
Values (Forms!MainFormName!txt_MyTextField, ... )
does work in a query in the Access GUI, but not in a vba query definition specified with the following code:
Set query_definition = CurrentDb.CreateQueryDef("", SQLQuery))
"Forms!MainFormName!NameOfSubformNavigationElement!txt_MyTextField" does not work either as a reference, just in case you are wondering. Neither does "Forms!MainFormName!NameOfSubformNavigationElement.Form.txt_MyTextField"
How can I get what I want? The string can have any kind of special chars like ' and ". Is there no alternative than appending the user input into the sql query? Is there some built-in function to escape these values?
UPDATE: Added another example now that the environment is known.
To use the form field in an action query, create a public function that will return the desired field, then call that function from your query.
Public Function GetFormField() As String
GetFormField = Forms![MyMainForm]!MySub.Form.MyField
End Function
In your query, use something like:
WHERE ((([106thZip_code_database].zipcode)=GetFormField()));
The following is an example you could use in the Main form to reference a field in a subform. 'MySub' is the name of the control on the Main form - not the subform's object name.
Debug.Print Forms![MyMainForm]!MySub.Form.MyField
A good reference on this subject can be found at: http://access.mvps.org/access/forms/frm0031.htm
I have the following:
<telerik:GridBoundColumn HeaderText="Name(s)" UniqueName="colNames" DataField="NameList"
AllowSorting="false">
the data being bound to this is coming from a SQL stored procedure that I can't modify without affecting a number of other pages. I need to sort these items by a substring; the field to be displayed is 'Firstname Lastname', and I need to sort on last name. Is there a way to modify the above to sort on the substring after ' '? I know this is an imperfect solution to finding the last name (F. Murray Abraham == 'M') but that's the approach that I'm tasked to implement.
I'm trying to use the Telerik SortExpression but can't get the syntax figured out (assuming that it's even usable for this purpose).
If it helps, the site codebehind is built in VB.NET.
The best way is to modify the stored proc by adding new column to the returned dataset which contains the last name, provided the last name column is defined separately from the first name. This won't affect other pages which are already using the stored proc, unless you use AutoGeneratedColumn for the RadGrid on those pages.
If the name column returned from the stored proc is in full format (i.e "John Smith") and/or there is no way you can add field to the returned dataset from the stored proc, you will have to do this in code-behind:
Execute the stored proc and fill a DataTable with the returned dataset
add a new column 'LastName' of type String to the DataTable object
For each row in DataTable, extract the lastname from the "NameList" column
assign it to the 'LastName' column
set the modified DataTable object to your RadGrid.DataSource
Remember to add SortExpression="LastName" to your GridBoundColumn tag above and AllowSorting="true".
To extract the last name:
If Not IsDBNull(row!NameList) Then
Dim nameparts() As String = Cstr(row!NameList).Split(New Char() {" "c}, StringSplitOptions.RemoveEmptyEntries)
If nameparts.Count > 0 Then
row!lastname = nameparts.GetUpperBound(0)
End If
End If
I'm trying to create a custom script in SSIS 2008 that will loop over the selected input columns and concatenate them so they can be used to create a SHA1 hash. I'm aware of the available custom components but I'm not able to install them on our system at work.
Whilst the example posed here appears to work fine http://www.sqlservercentral.com/articles/Integration+Services+(SSIS)/69766/ when I've tested this selected only a few and not all columns I get odd results. The script only seems to work if columns selected are in sequential order. Even when they are in order, after so many records or perhaps the next buffer different MD5 hashes are generated despite the rows being exactly the same throughout my test data.
I've tried to adapt the code from the previous link along with these articles but have had no joy thus far.
http://msdn.microsoft.com/en-us/library/ms136020.aspx
http://agilebi.com/jwelch/2007/06/03/xml-transformations-part-2/
As a starting point this works fine to display the column names that I have selected to be used as inputs
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
For Each inputColumn As IDTSInputColumn100 In Me.ComponentMetaData.InputCollection(0).InputColumnCollection
MsgBox(inputColumn.Name)
Next
End Sub
Building on this I try to get the values using the code below:
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
Dim column As IDTSInputColumn100
Dim rowType As Type = Row.GetType()
Dim columnValue As PropertyInfo
Dim testString As String = ""
For Each column In Me.ComponentMetaData.InputCollection(0).InputColumnCollection
columnValue = rowType.GetProperty(column.Name)
testString += columnValue.GetValue(Row, Nothing).ToString()
Next
MsgBox(testString)
End Sub
Unfortunately this does not work and I receive the following error:
I'm sure what I am trying to do is easily achievable though my limited knowledge of VB.net and in particular VB.net in SSIS, I'm struggling. I could define the column names individually as shown here http://timlaqua.com/2012/02/slowly-changing-dimensions-with-md5-hashes-in-ssis/ though I'd like to try out a dynamic method.
Your problem is trying to run ToString() on a NULL value from your database.
Try Convert.ToString(columnValue) instead, it just returns an empty string.
The input columns are not guaranteed to be in the same order each time. So you'll end up getting a different hash any time the metadata in the dataflow changes. I went through the same pain when writing exactly the same script.
Every answer on the net I've found states to build a custom component to be able to do this. No need. I relied on SSIS to generate the indexes to column names when it builds the base classes each time the script component is opened. The caveat is that any time the metadata of the data flow changes, the indexes may change and need to be updated by re-opening and closing the SSIS script component.
You will need to override ProcessInput() to get store a reference to PipelineBuffer, which isn't exposed in ProcessInputRow, where you actually need to use it to access the columns by their index rather than by name.
The list of names and associated indexes are stored in ComponentMetaData.InputCollection[0].InputColumnCollection, which needs to be iterated over and sorted to guarantee same HASH every time.
PS. I posted the answer last year but it vanished, probably because it was in C# rather than VB (kind of irrelevant in SSIS). You can find the code with all ugly details here https://gist.github.com/danieljarolim/e89ff5b41b12383c60c7#file-ssis_sha1-cs
I have stored proc Im pulling in to excel but to get it to Run I have to enter my text exec roc 'Name' I need it to be able to have someone else thats running it be able to enter a name as they refresh the data. I dont know VBA at all and am looking for help.
I don't completely understand your question but if my assumption is correct... you want to have a cell where someone can enter some sort of name, where you can then use their input to do some other operations.
To start, you would want to grab a string variable (by grab I mean create)
Example:
Dim strName As String
Then you would want to be able to read a specific cell.... In the next example the cell will be A2
Example:
strName = Range("Sheet1!A2").Value
If you named the first sheet something different use that name. If the user inputs a name into that cell you can then use it later to do calculations or anything you want.
If you are not using VBA code then what are you using?
If using MS Query, try changing the SQL text to
{CALL roc(?)}
and IIRC this should prompt the user to enter text for the parameter value.