Syntaxe incorrecte à proximité de l'instruction IF

J'utilise une instruction IF afin de choisir une colonne qui n'est pas NULL dans une procédure SQL SELECT. Cependant, j'obtiens une erreur disant qu'il y a quelque chose qui ne va pas avec ma syntaxe près du mot-key IF.

DECLARE @imgURL_prefix VARCHAR(100) DECLARE @imgSmall_Suffix VARCHAR(100) DECLARE @imgLarge_Suffix VARCHAR(100) SET @imgURL_prefix = '//sohimages.com/images/images_soh/' SET @imgSmall_Suffix = '-1.jpg' SET @imgLarge_Suffix = '-2.jpg' SELECT P.ProductCode as ProductCode, P.HideProduct as HideProduct, P.Photos_Cloned_From as Photos_Cloned_From, @imgURL_prefix + LOWER( IF P.Photos_Cloned_From IS NOT NULL P.Photos_Cloned_From ELSE P.ProductCode END ) + @imgSmall_Suffix as PhotoURL_Small, @imgURL_prefix + LOWER( IF P.Photos_Cloned_From IS NOT NULL P.Photos_Cloned_From ELSE P.ProductCode END ) + @imgLarge_Suffix as PhotoURL_Large, P.PhotoURL_Small as OriginalSmall, P.PhotoURL_Large as OriginalLarge FROM Products_Joined P 

Le script fonctionne LOWER(P.ProductCode) sans l'instruction IF, en utilisant juste LOWER(P.ProductCode) à sa place.

Vous pouvez utiliser IIF(Expression, true, false) dans sql server 2012 et versions ultérieures et pour les anciennes éditions vous avez l'instruction CASE

 /********* SQL SERVER 2012+ ***********/ SELECT P.ProductCode as ProductCode, P.HideProduct as HideProduct, P.Photos_Cloned_From as Photos_Cloned_From, @imgURL_prefix + LOWER( IIF( P.Photos_Cloned_From IS NOT NULL , P.Photos_Cloned_From, P.ProductCode)) + @imgSmall_Suffix as PhotoURL_Small, @imgURL_prefix + LOWER( IIF (P.Photos_Cloned_From IS NOT NULL, P.Photos_Cloned_From, P.ProductCode)) + @imgLarge_Suffix as PhotoURL_Large, P.PhotoURL_Small as OriginalSmall, P.PhotoURL_Large as OriginalLarge FROM Products_Joined P /********* SQL SERVER Older Versions ***********/ SELECT P.ProductCode as ProductCode, P.HideProduct as HideProduct, P.Photos_Cloned_From as Photos_Cloned_From, @imgURL_prefix + LOWER( CASE WHEN P.Photos_Cloned_From IS NOT NULL THEN P.Photos_Cloned_From ELSE P.ProductCode END) + @imgSmall_Suffix as PhotoURL_Small, @imgURL_prefix + LOWER( CASE WHEN P.Photos_Cloned_From IS NOT NULL THEN P.Photos_Cloned_From ELSE P.ProductCode END) + @imgLarge_Suffix as PhotoURL_Large, P.PhotoURL_Small as OriginalSmall, P.PhotoURL_Large as OriginalLarge FROM Products_Joined P