DbUp - Loop script for different variable values - dbup

I'm trying to loop on a list of ID's in order to execute the same query with its different values.
I was thinking about using IScript to create this loop using C#, but I don't have access to the variables that are passed when using .WithVariable().
Is there any way to perform this action?

Related

Is there any unique id for each time ForEach Loop executes in ssis packages?

I want to have a unique id for every time ForEach Loop Container executes in ssis packege,because i follow a serial steps like a flow and i want to have them under a unique key,I know i can Generate that key myself, but i think it might have a system variable that comes in handy in such a situation.
If you check the following documentation:
System Variables for Containers
You can see that there is no system variables that store this information. On the other hand, you can refer to the following answer if you need to do it manually:
Display foreach loop iteration number in SSIS
According to Microsoft Documentation on System Variables, there is a variable System::ContainerStartTime. As the ForEach Loop is a container, you can convert DateTime value of the variable from above to a serial number, like number of seconds since 1st of Jan 1900, and use it as a sequence ID. On its own it is not completely unique; any other instance of the same package running simultaneously can generate the same seq. ID. So, it might be sufficient if you are not running same package twice.
You can make it unique mixing with System::ExecutionInstanceGUID, but it requires some coding.

print or select inside SQLServer function

In SQLServer sometimes following the code without debugging is necessary. It is possible with print statement or with select statement. The problem is SQLServer does not allow these methods within the functions. That makes the complex function like the black box. I have tried to use write the messages to the text file with stored procedure within the function, however, it doesn't allow either.
Is there any way to track my code like print statement within the function.
Your statement
The problem is SQLServer does not allow these methods within the functions
is the problem and the answer at the same time. Yes: This is not allowed within functions.
When I've to deal with larger function code, I usually copy this code into a query window and test it externally. Doing so, you can use PRINT or SELECT ... INTO or any other approach to save some intermediate values.

Updating/Changing huge table in access via vba

I imported a table into access via vba as dao. Now I need to run a couple of replacements and updates of some table values.
This includes:
- mapping/replacement of Strings (i.e., replace all "ABB" with "Read-Only", "AAB" with "Write", etc.)
- remove leading Strings (i.e. cut leading "_customname")
As I have to work with a HUGE table, I am in need of the fastest approach:
Should I run simple update queries within VBA?
Should I go for a line-by-line approach with an "if then apprach"?
Should I already change the value during the import process?
Or is there a better solution after all?

SQL Server 2008 - Save each "while loop" result to a different file

I'm using a double while loop to get a lot of results from several different tables. I get everything I need (500+ subjects, each with 1000+ rows), but each comes into a different grid. I would like to save each "while" result to a different .csv file. Is there any way
Might be possible to do using SQLCMD or BCP, but will be quite cumbersome to code, using quite a few variables and dynamic SQL.
If faced with this scenario, I would personally go with an SSIS package -
Use package variables to generate destination filenames dynamically
Use a for each loop container instead of the while loop
Put a dataflow task inside the container and use the Select code as source and the file from step one as the destination
It is pretty easy to do.

SSIS: Can I edit my recordset as I loop through it using the foreach statement?

I am using SSIS to make a series of complicated data exports, and I've hit a roadblock. I've populated a package variable with a recordset. I'd like to use a foreach loop to iterate through each row in the recordset. I'd like to update one of the columns in each row based on some calculations which I've done inside a script task.
Is this possible? I know in C# the foreach collection is immutable, but I don't know if SSIS works the same way.
Unfortunately, I haven't found any good examples of using the for loop construct instead, which might be a potential solution.
When you put data into a recordset it's stored in an object variable. You can use the Foreach Loop Container - and loop the object variable. You then create some variables to hold each column for the row - and you then have a row-by-row ability to do whatever you please, be it a data flow task, sql statement, script task (c#) or anything else.
See http://www.sqlis.com/post/Shredding-a-Recordset.aspx for an illustrated example of how to do this and send an email for every row.

Resources