0

I am a bit new to SSIS and given a task to send mail to particular stores based on Purchase Orders -> PONumber.

The steps should be as follows:

1)Take a XML file from a particular folder

2)Get the PONumber from that file

3)Write a query to fetch all the store email addresses for PONumbers

4)Send a mail to particular restaurant

Below screenshot is a package I had created. The only thing I am getting an issue is the Execute SQL Task , not sure what is the exact cause?

Could you please help on how can I debug this ? This was working fine before, but suddenly it started showing errors.

IMAGE1

IMAGE5

Shivang
  • 231
  • 1
  • 5
  • 17

2 Answers2

0

Execute SQL task is expecting results from the query, but is not getting any. Maybe you could use SQL Server profiler to catch exact SQL that is executed on SQL Server. Then you can use that SQL in query window to troubleshoot what it returns or why it is not not giving any results.

Edit. With your current additional information interesting place is "parameter mapping" page, which you did not include. You should link SSIS variable to query parameter in there as Matt explained. SSIS does NOT link your variables in SSIS and query automatically even if they have the same names.

dvlpr
  • 31
  • 5
  • HI please see the code above in SQL Execute Task and SSMS. It ran fine on SSMS but not on SQL Execute task. – Shivang Sep 12 '16 at 13:43
  • not sure why this answer got down voted by someone it is right the problem is OP is not getting results and at the time of being answered there was no additional information that could lead the community to determine a more exact cause. – Matt Sep 12 '16 at 15:45
0

@dvlpr is correct your problem is you are getting NO results when Execute SQL Task 1 needs a single result.

The code you pasted is a little unclear as to which code is where but I will assume the first part is the code you use in SSIS Execute Task and the latter is an example in SSMS. If that is the case the problem is you are assigning the variable with a value of 0 in the script itself which I assume there is no PONUMBER that is 0:

Declare @POID as Varchar(50)
Set @POID = 0
WHERE    (BizTalk_POA_HEADER.PONUMBER = @POID)

If you want to pass in the PONUMBER from your first dataflow task you need to load that to a variable and then use the variable in your Execute SQL task and made sure you setup parameter mapping correctly when doing so. here is one SO question on parameters that will help How to pass variable as a parameter in Execute SQL Task SSIS? And here is use of an expression task in a Data Flow task to set the variables value SSIS set result set from data flow to variable (note use the non-accepted answer that it was added later and was for 2012+ while the original was for 2008)

Next unless you are guaranteed only 1 result you will also need to add TOP 1 to your select statement because if you get more than 1 result you will get a different error again.

EDIT Per all of the comments:

So the configuration looks like you are using an ADO.NET connection which allows you to use named paramaters. There are restrictions if you don use that (https://msdn.microsoft.com/en-us/library/cc280502.aspx). The parameter mapping looks correct, and the result set should be fine. As far as your Error I don't know because you haven't posted the exact error so I cannot know what is the problem. If you use ADO.Net with your current Execute SQL Task configuration in the images you do have a couple of problems. 1 you are trying to declare the variable that you want to pass as a parameter that doesn't work, you need to remove that DECLARE statement. I suspect all you really need to do is modify your SQL Input to be:

SELECT    DISTINCT  BizTalk_POA_HEADER.PONUMBER, FAN_Suppliers.SupplierName,      
FAN_Company_Details.CompanyName, FAN_Company_Details.[PrimaryEmail],   
BizTalk_POA_HEADER.[DeliveryDate]
FROM BizTalk_POA_HEADER INNER JOIN
FAN_PO_Details ON BizTalk_POA_HEADER.PONUMBER =   
CONCAT('PO',FAN_PO_Details.PoNumber) INNER JOIN
FAN_PO ON FAN_PO_Details.PurchaseOrderID = FAN_PO.PurchaseOrderID 
INNER JOIN FAN_SupplierDetails ON FAN_PO.SupplierDetailsID =    
FAN_SupplierDetails.SuppliersDetailsID INNER JOIN
FAN_Suppliers ON FAN_SupplierDetails.SupplierID = FAN_Suppliers.SupplierID  
INNER JOIN FAN_Company_Details ON FAN_PO.CompanyID =   
FAN_Company_Details.CompanyDetailsID
WHERE    (BizTalk_POA_HEADER.PONUMBER = @POID)

Just get rid of the declare @POID and SET = 0 for a couple of reasons 1 because it is redundant when you have setup parameter mapping, 2 SSIS doesn't like it and will throw an error, 3 because you are setting a value of 0 to it which means it would always be 0.....

Community
  • 1
  • 1
Matt
  • 13,833
  • 2
  • 16
  • 28
  • Hi Matt, Thanks but I hve added an extra screenshot above which has a result set and PONUMBER included in it. Do I need to still pass a parameter? – Shivang Sep 13 '16 at 00:12
  • The screen shot shows result set not parameter. Parameter Mapping is where you would define the value to be used. And if you follow the first link "how to pass..." you will see how to do so. Using a ? instead of named parameter is probably easiest but you will have to know which order the ? marks are in. I would recommend pasting your exact Execute SQL Task and which variables you want to paste as variables if you have further difficultly. – Matt Sep 13 '16 at 00:34
  • Hi Matt, I have added the Execute SQL Task which has all properties in it. The Execute SQL Task code is the first one which you identified that starts with Declare POID as varchar.... – Shivang Sep 13 '16 at 01:19
  • Matt any thoughts on the above? – Shivang Sep 13 '16 at 04:48
  • The screen shots still show the result set, the "Parameter Mapping" is the problem. You keep showing the configuration of how to get returned data you need to show the configuration for how you are passing a parameter. Coincidentally you are using the PONUMBER variable as the result and parameter which probably isn't the best idea but as long as it is the same it shouldn't matter. Follow the first link in my answer to see what I am referring to. – Matt Sep 13 '16 at 15:09
  • Hi Matt, Please see the parameter mapping now I added and guide me through this error. It says "[Execute SQL Task] Error: Executing the query "Declare @POID as Varchar(50) Set POID = 312993 " failed with the following error: "Could not find stored procedure ''.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly." As said in configs I tried to use connection as ADO.net and the query was the same. I have pasted parameter as IMAGE 5 – Shivang Sep 14 '16 at 02:12
  • see edits, I am moving on from this question though. if you want additional troubleshooting you need to post ALL relevant parts of your package and Execute SQL task because, as well as full error detail/text the community is guessing a little here. – Matt Sep 14 '16 at 15:47