Question : SSIS Case Statement not executing

Hi Guys,

I am trying to run an SQL SELECT CASE statement in an Execute SQL Task in SSIS and I dont understand why it is erroring.

If i run the following code to prove the varaiable and prarmeters are working fine then it all works okay and I get the variable value in the Items field.

UPDATE ImpPricesSys21 Set Item = ?

Now I want to carry out a specific SQL command to update certain records based on the parameter input. When I run the following

SELECT CASE
 WHEN ? = 'E:\Web_FTP_home\WEBPRICEDUMP\001_Prices.txt' THEN UPDATE ImpPricesSys21 SET [Item] = 'AA'
 WHEN ? = 'E:\Web_FTP_home\WEBPRICEDUMP\002_Prices.txt' THEN UPDATE ImpPricesSys21 SET [Item] = 'BB'
 WHEN ? = 'E:\Web_FTP_home\WEBPRICEDUMP\003_Prices.txt' THEN UPDATE ImpPricesSys21 SET [Item] = 'CC'
END

I get the following error...

Error: 0xC002F210 at Execute SQL Task, Execute SQL Task: Executing the query "SELECT CASE
 WHEN ? = 'E:\Web_FTP_home\WEBPRICEDUM..." failed with the following error: "No value given for one or more required parameters.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.

Any thoughts on where I am going wrong?

Look forward to your assistance.

Nigel

Answer : SSIS Case Statement not executing

Correction, select is not required

UPDATE ImpPricesSys21 SET [Item] =
CASE ?
 WHEN 'E:\Web_FTP_home\WEBPRICEDUMP\001_Prices.txt' THEN 'AA'
 WHEN 'E:\Web_FTP_home\WEBPRICEDUMP\002_Prices.txt' THEN 'BB'
 WHEN 'E:\Web_FTP_home\WEBPRICEDUMP\003_Prices.txt' THEN 'CC'
 ELSE [Item]
END

Your original WHEN form works as well, but a bit more repetitive with the variable.  Also the ELSE preserves [Item] when none of the cases are met, otherwise it is equivalent to the implicit ELSE NULL.

UPDATE ImpPricesSys21 SET [Item] =
CASE
 WHEN ? = 'E:\Web_FTP_home\WEBPRICEDUMP\001_Prices.txt' THEN 'AA'
 WHEN ? = 'E:\Web_FTP_home\WEBPRICEDUMP\002_Prices.txt' THEN 'BB'
 WHEN ? = 'E:\Web_FTP_home\WEBPRICEDUMP\003_Prices.txt' THEN 'CC'
 ELSE NULL
END
Random Solutions  
 
programming4us programming4us