【发布时间】:2014-12-24 22:13:11
【问题描述】:
我正在使用 IF 语句来选择 SQL SELECT 过程中不为 NULL 的列。但是,我收到一条错误消息,提示我在关键字 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
脚本可以在没有 IF 语句的情况下正常工作,只使用 LOWER(P.ProductCode) 代替它。
【问题讨论】:
-
啊,谢谢。这解决了它。
标签: sql sql-server if-statement