Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 SSIS and Import/Export (2012)
 Using variable in Execute SQL task
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Aged Yak Warrior

United Kingdom
550 Posts

Posted - 09/11/2013 :  08:05:00  Show Profile  Reply with Quote
Hello there, I have mapped a variable in a Execute SQL task,

The parameter name is 0

I am using the below script

declare @fileVariable varchar(100)
declare @file varchar(100)

set @fileVariable = ?

select @file = SUBSTRING (@fileVariable, CHARINDEX('r\cu', @fileVariable) +1, LEN(@fileVariable))

select @file = right(@file, len(@file) -charindex('\', @file))

delete customer_staging where filename = @file

and I get the following error

The query failed to parse. The batch could not be analysed because of compile errors.

The code works fine ssms, could someone point me in the right direction please.



Posting Yak Master

160 Posts

Posted - 10/10/2013 :  10:20:43  Show Profile  Reply with Quote
Check ByPassPrepare property for Execute SQL Task.

Refer to ..

You may have ByPassPrepare set to false. Cannot parse due to parameter.
Go to Top of Page

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 10/10/2013 :  10:27:31  Show Profile  Reply with Quote
You may be better off making code batch a procedure and then making filevariable as a parameter Then call it as

EXEC Procname ?
and then map parameter 0 to your variable.
This worked for me

SQL Server MVP
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000