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)
 SSIS - Variable Substitution
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

SSIS_Beginner
Starting Member

4 Posts

Posted - 02/15/2013 :  14:53:40  Show Profile  Reply with Quote
I am having issues refining a query within a SSIS “Execute SQL” task and was wondering if anyone could help. The ultimate goal is to take an XML file content from directory and load it into a SQL DB table along with the file name and date. I have a for-each loop container to loop through the directory with a variable to hold the file name. In my “Execute SQL” task I have 3 parameters set up – “filename, Path, filename” consecutively numbered from 0 to 2 in the Parameter name fields. When I add the 2nd and 3rd question mark for the path and filename I get the error: "Multiple-step OLE DB operation generated errors” – here is my query –

INSERT INTO ifo_xml(xml_file_name, xml_contents, load_time)
SELECT '?', xmlData, getdate()
FROM(SELECT * FROM OPENROWSET (BULK ''?'+'?'',SINGLE_BLOB) AS XMLDATA) AS FileImport (XMLDATA)

Here is the catch!
I can run the query below successfully when I use the first variable question mark and hard code the path with the files name. So otherwise the bulk load is successful and the columns in the DB table are correct.

INSERT INTO ifo_xml(xml_file_name, xml_contents, load_time)
SELECT '?', xmlData, getdate()
FROM(SELECT * FROM OPENROWSET (‘\\myserver\ filemname.xml’ ,SINGLE_BLOB) AS XMLDATA) AS FileImport (XMLDATA)

When I add the additional question marks to substitute for the path and filename I get the error.

Any help would be appreciated.

SSIS_Beginner

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 02/15/2013 :  14:59:08  Show Profile  Reply with Quote
whats the datatype you used for those variables?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

SSIS_Beginner
Starting Member

4 Posts

Posted - 02/19/2013 :  17:38:37  Show Profile  Reply with Quote
I have tried both NVARCHAR and VARCHAR for the variables.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 02/20/2013 :  01:39:10  Show Profile  Reply with Quote
why not pass the entire filename with path through a single variable? Add a variable for full path in SSIS, make EvaluateExpression property true and give value as path variable + filename variable. then use this new fullpath variable to substitute for single ? after BULK clause

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

SSIS_Beginner
Starting Member

4 Posts

Posted - 02/20/2013 :  11:26:35  Show Profile  Reply with Quote
I did put the path and file name variable in an expression and use it in the query - I received the same error: "Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done." - below is the query used:
INSERT INTO ifo_xml(xml_file_name, xml_contents, load_time)
SELECT '?', xmlData, getdate()
FROM (SELECT * FROM OPENROWSET (BULK ''?'' , SINGLE_BLOB) AS XMLDATA) AS FileImport (XMLDATA)

Any other thoughts?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 02/20/2013 :  13:18:41  Show Profile  Reply with Quote
can you try putting whole query inside variable by using expression builder and then use variable option in execute sql task?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

SSIS_Beginner
Starting Member

4 Posts

Posted - 02/22/2013 :  09:48:36  Show Profile  Reply with Quote
Strangely I found that this works:

EXEC ('
INSERT INTO ifo_xml(xml_file_name, xml_contents, load_time)
SELECT ''' + ? + ''', xmlData, getdate()
FROM(SELECT * FROM OPENROWSET (BULK ''' + ? + ? + ''' , SINGLE_BLOB) AS XMLDATA) AS FileImport (XMLDATA)
')

I am not sure why this works and not my previous code that is similar.

thanks for your suggestions.
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