all groups > sql server dts > october 2004 >
You're in the

sql server dts

group:

Using global variable in ExecuteSQL task


Using global variable in ExecuteSQL task Mark Peterson
10/27/2004 10:03:59 AM
sql server dts:
I'm attempting to execute several DELETE statements via an ExecuteSQL task.
I need to access a global variable that's set earlier in the package. I've
gotten this to work for simpler queries, but for this particular set of SQL
statements, I'm getting the following errors:

Error Source: Microsoft OLEDB Provider for SQL Server
Error Description: The column prefix 'Payee' does not match with a table
name or alias name used in the query. (repeated 4 times)

Here's the query...

DELETE AssignedPayee
FROM AssignedPayee INNER JOIN Payee ON AssignedPayee.PayeeID = Payee.ID
WHERE Payee.BranchID = ?

DELETE PayeeAddress
FROM PayeeAddress INNER JOIN Payee ON PayeeAddress.PayeeID = Payee.ID
WHERE Payee.BranchID = ?

DELETE PayeeDeduction
FROM PayeeDeduction INNER JOIN Payee ON PayeeDeduction.PayeeID = Payee.ID
WHERE BranchID = ?

DELETE FROM Payee
WHERE BranchID = ?

At first, I had written these queries using subqueries, such as...

DELETE FROM AssignedPayee
WHERE PayeeID IN (SELECT ID FROM Payee WHERE BranchID = ?)

[quoted text, click to view]
the queries as shown above.

Any ideas on how to get this to work?

Thanks!
Mark


Re: Using global variable in ExecuteSQL task Allan Mitchell
10/28/2004 7:58:08 PM
If you move each DELETE out to its own task?

Who owns Payee?



--
--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.SQLDTS.com - The site for all your DTS needs.
www.konesans.com - Consultancy from the people who know


[quoted text, click to view]

Re: Using global variable in ExecuteSQL task Mark Peterson
10/29/2004 7:11:42 AM
All tables are owned by dbo. I did find a way to workaround this by adding
an ActiveScript task right before this task. The ActiveScript task
dynamically bulids the SQL statements and then populates this ExecuteSQL
task. Works great.

The entire package has 80+ steps at the moment - about 25 of those are
ExecuteSQL statements of various types. Of those 25 taks, I had 4 where the
SQL queries were complex enough where I had to use the workaround I
mentioned above. They all involved various subqueries of some sort.

For example, I had a task with just this one delete statement:

DELETE FROM Bonus WHERE LeaseID IN
(SELECT ID FROM Lease WHERE AccountID IN
(SELECT ID FROM Account WHERE BranchID = ?))

No matter how I wrote this query in the ExecuteSQL task, I couldn't get it
to accept the parameter, so I used the ActiveScript task to build the
statement at runtime based on the global variable.

- Mark

[quoted text, click to view]

AddThis Social Bookmark Button