SELECT
a.componentId, a.uniqueCode,
'sd'= CASE
WHEN RTRIM(LTRIM(b.name)) IS NULL OR RTRIM(LTRIM(b.uniqueCode)) IS NULL
THEN isnull(b.uniqueCode,'')+isnull(b.name,'')
WHEN RTRIM(LTRIM(b.name)) IS NULL AND RTRIM(LTRIM(b.uniqueCode)) IS NULL
THEN isnull(b.uniqueCode,'')+isnull(b.name,'')
ELSE b.uniqueCode + '(' + (b.name) + ')'
END,
a.specialization
FROM Doctors a
LEFT OUTER JOIN Territories b ON a.locationId = b.componentId;
假设b.uniqueCode = T003
和b.name = Dhanmondi 01
,然后sd
应该是T003(Dhanmondi 01)
。SQL服务器:CASE不起作用
现在如果b.name = NULL
那么SD应该是T003
,但我的查询结果显示T003()
。
我的T-SQL查询出了什么问题?
疯狂猜测:在转换到SQL-Server之前,您是否使用过Oracle? :) –