SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

masterdineen
Aged Yak Warrior

United Kingdom
548 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.

Regards

Rob

tm
Posting Yak Master

154 Posts

Posted - 10/10/2013 :  10:20:43  Show Profile  Reply with Quote
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

India
52309 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
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.06 seconds. Powered By: Snitz Forums 2000