I have foreach loop for excel files. The matter is I need truncate table and extract new rows only if there is any file. If not, process is being continued without foreash loop.
I configured control flow and data flow and it works if there are any file, but if don't I get an error.
Control Flow
I want to handle two situations: 1) When any file exists in directory -> truncate table and do data flow. 2) If directory is empty ( 0 .xlsx files) omit whole process and continue next tasks.
Related
I've been trying to create a function to load some files insert them into a temp table based on an existing table, then verifying that there are not duplicated rows on the files loaded and then inserting them into proper tables in the DB, tried using something like this:
let statement = " select * from ", vtable clipped, " where 1=0 into temp t_",vtable clipped
prepare pstatement from statement
execute pstatement
to no avail because the temp table seems to be created on a different session than the one im working in.
Any suggestions?
Thank you all beforehand
If you prepare and execute a statement as shown, it is created on the connection you're using at the time. If you don't mess with the connections (CONNECT, DISCONNECT, SET CONNECTION), then it should all be clean — if the statement worked at all. Are you checking errors (WHENEVER ERROR STOP, perhaps)? Or have you displayed statement to ensure the SQL is as expected (no untoward chopping of the string, for example — that could account for why the table appears to be missing).
Remember that a temporary table is private to the session. If you run a LOAD statement in the I4GL program, there should be no problem, but you can't use a separate loader program with a temporary table. In terms of the database, it would have to be a 'permanent' or 'regular' table, even if you remove it soon after creating it.
You could also prepare an explicit CREATE TEMP TABLE statement to create a table.
Also consider whether using an external table would help you with the loading. There are also violations tables that could be used to trap problematic rows while loading directly into the main table.
I have a script control which splits my data down two file streams and into two File Destinations. Unfortunately even if there are no records for one of the streams the destination file Is still created. How can this be prevented.
Well this is how the SSIS behaves i.e. creating destination files even if there is no data. You would need a workaround to get this through -
Insert a 'Row Count' transformation between Script Task and your 'Destination File' and assign a variable to it say #intNumberOfRows.
Connect the Data Flow Task to a 'File Task' to delete the empty file created by using a conditional expression based on the value of #intNumberOfRows set to 0.
I'm trying to make a watchfolder application using Delphi 2010.
On the main form I added 2 listbox and a timer.
I list all files from a specific folder.
At every 5 seconds i perform a check over the files from a listbox to see which file is still in use.
Listbox1 holds the files that are in use and listbox2 holds the files that are not in use.
If there is a file that is being used(ex: it is still being copied to the folder) i add it to listbox1.
If the files from that folder that i monitor are not in use then I add them to listbox2.
The problem is that I perform a loop over listbox2 in order to send all the files listed to a ftp (for i:=0 to listbox2.items.count-1 do ....).
If i add one more file to listbox2 while performing the loop I get the "List index out of bounds"?
How can i add an item to listbox2 loop while performing the loop?
Thanks a lot?
Any other suggestion regarding the watchfolder ideea?
A for loop's control value is evaluated only once, at the beginning of the loop. Adding entries to the list should not be causing a bounds error, as the Count will not be shrinking. The loop will stop when it reaches the old Count. However, removing an item would shrink the Count and thus cause a bounds error once the loop exceeds the new Count trying to reach the old Count.
That being said, the solution is simple - DO NOT modify the ListBox while you are looping through its content! You will have to either:
delay any modifications until after the loop has finished.
copy the current ListBox content to a separate TStringList and loop through that instead of the ListBox directly, then you can do whatever you want to the ListBox while the loop is busy.
We're trying to make a DTS package where it'll launch a stored procedure and capture the contents in a flat file. This will have to run every night, and the new file should overwrite the existing file.
This wouldn't normally be a problem, as we just plug in the query and it runs, but this time everything was complicated enough that we chose to approach it with a stored procedure employing temporary tables. How can I go about using this in a DTS package? I tried going the normal route with the Wizard and then plugging in EXEC BlahBlah.dbo... It did not care for that:
The Statement could not be parsed. Additional information: Invalid object name '#DestinyDistHS'. (Microsoft SQL Server Native Client 10.0)
Can anyone guide me in the right direction here?
Thanks.
Is it an option to simply populate a non-temp table in your SP, call it and select from the non temp table when exporting?
This is only an issue if you have multiple simultaneous calls to the stored procedure. In this case you can't save to a single table.
If you do have multiple simultaneous calls then you might be able to:
Create a temp table to hold results
Use INSERT INTO #TempTable EXEC YourProc
SELECT FROM #TempTable
You might need to do this in a more forgiving command line tool (like SQLCMD). It's not as fussy about metadata.
I am using ESQL/C code to provide backend support for a UI, connecting to an Informix database. I am creating temp table inside my code. But, I guess that if multiple users use this UI at the same time then temp table might already exist in the database which can create problem. So, can someone suggest if I can create temp table with PID as suffix inside my ESQL/C code
create temp table tabname_PID (name char(10));
In shell script I generally use tabname_$$.
You can create the table with the PID embedded in it, but it isn't necessary. Any temporary table is only visible in the session that creates it, so you can use the same table name in each session (separate but concurrently executing ESQL/C program) without any fear of conflict.
If, despite the reassurances that it is unnecessary, you still want to do it, then you'll have to PREPARE and EXECUTE (or DECLARE, OPEN, FETCH, CLOSE) the statements from a string:
snprintf(sql, sizeof(sql), "CREATE TEMP TABLE tabname_%d(name CHAR(10))", (int)getpid());
EXEC SQL PREPARE s FROM :sql;
EXEC SQL EXECUTE s;
or use EXECUTE IMMEDIATE (which is the obvious winner here):
EXEC SQL EXECUTE IMMEDIATE :sql;
You will also then have to prepare all the queries; one distinct advantage of using the fixed-name temporary table is that you don't have to prepare everything that references the temp table if you don't want to (though there are often advantages to using PREPARE etc).
You don't have to use $$ in shell scripts either, for the same reason — temporary tables are private to a session.