Search code examples
ssis-2012

Invalid SQL statement; expected DELETE, INSERT, PROCEDURE, SELECT, or UPDATE?


I'm using this code to read data but ,it's not working. Can any one correct this code,I'm using this code in variable and run that variable by Execute SQL task.

"IF (LEFT( @[User::FileName] ,3))='PWR' "+" SELECT * FROM  "+ "["+@[User::SheetName]+"A36:T]"
+" ELSE "+
"SELECT * FROM  "+ "["+@[User::SheetName]+"A35:T]"  

Solution

  • Now I got the solution ,Let me explain the scenario. We are getting around 100 unformatted Excel files on daily basis ,where file name either start with "SRW" or "PWR".In 'PWR' data is start from A36 row and in 'SWR' A35 Cell. I'm storing all the file name into a SQL table and then reading all the file using for each loop container and loading the data into table. Now I'm assing a variable with below query and calling that variable in Execute SQL task.

    LEFT(@[User::FileName],3)=="PWR" ? " SELECT * FROM "+ "["+@[User::SheetName]+"A36:T]" : "SELECT * FROM "+ "["+@[User::SheetName]+"A35:T]"

    enter image description here

    Now I'm using this query 2 as a variable in SQL command.

    enter image description here