3

I am trying to perform a pretty basic process:

  • (Reset) Truncate Table
  • Loop Through Folder of Files
  • Check to See if FileName Exists in FILES Table
  • If Not, Import Data from File Into DATA Table
  • Insert FileName into FILES Table

I can get it to go through the folder of files, load them, and insert the filename into the table. However, I cannot get the constraint to work so that it ONLY loads the files that are not already in the FILES table.

Here is my overall setup:

enter image description here

Variables:

enter image description here

Here's the ForEach Loop Setup:

enter image description here enter image description here

'File Exists in Table' SQL Task:

enter image description here enter image description here enter image description here

I tried:

SELECT COUNT(id) as id FROM PORG_Files WHERE filename = ?

I also tried a SqlStatementSource Expression of:

"SELECT COUNT(id) as id FROM PORG_Files WHERE filename = '" + @[User::CurrentFileName] + "'"

But I wasn't sure what to do with the SQLStatement under General while using the Expression.

Here is the Contstraint that always seems to be True:

enter image description here

I thought the issue was with the path formatting where the variable has double \s, but with the REPLACE to correct it, it isn't working.

For good measure, here is the 'Insert File into Table' SQL Task:

enter image description here enter image description here enter image description here

Files insert into the table just fine, here is how the table looks:

enter image description here

What the hell am I doing wrong?!?!

Thanks!!

4
  • \@id ==0, I think should be \@User::Id == 0 Commented May 24, 2019 at 9:40
  • Have you tried checking the variable values during execution? For example, adding a break point and then viewing the variables in the locals window? Commented May 24, 2019 at 14:28
  • @beibeizhu Using /@User::id gives a validation error. Using /@[User::id] validates, but still has the same issue. Commented May 24, 2019 at 18:09
  • @userfl89 - Yes, the User:CurrentFileName looks like \\\\erpsql\\p21shares\\purchasingsave\\item_3266_brianh.txt and the User::id never changes from 0 Commented May 24, 2019 at 18:10

3 Answers 3

1

Have you tried changing the ResultName id to 0.

You can take a look at the documentation for reference. enter image description here

Sign up to request clarification or add additional context in comments.

Comments

0

Change Input Parameter size

Try increasing the input parameter size in Execute SQL Task, since 100 may cause truncation. For a file path i will set it to 1000.

Using Expressions

But I wasn't sure what to do with the SQLStatement under General while using the Expression

When using expression, the SQLStatement in the General Tab don't have any value since it is changed at runtime.

Comments

0

It ended up being a few things.

  • The constraint did need to use @[User::id] == 0
  • I needed to use @[User::CurrentFileName] in the Query in the SQL Task
  • I did NOT need the REPLACE in the Query

Thank you, without the multitude of ideas I may not have figured it out!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.