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

 All Forums
 SQL Server 2012 Forums
 SSIS and Import/Export (2012)
 Using variable in Execute SQL task

Author  Topic 

masterdineen
Aged Yak Warrior

550 Posts

Posted - 2013-09-11 : 08:05:00
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.

Regards

Rob

tm
Posting Yak Master

160 Posts

Posted - 2013-10-10 : 10:20:43
Check ByPassPrepare property for Execute SQL Task.

Refer to .. http://www.sqlsafety.com/?p=196

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

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-10-10 : 10:27:31
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
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -