0

大家好,我有这个问题:

SELECT B.fld_ActionName,
    ISNULL(A.COUNT, 0) count,
    ISNULL(A.GRAMS, 0) grams,
    ISNULL(A.PRINCIPAL, 0) principal
FROM #PULLEDOUT A
RIGHT JOIN Reference.tbl_RefAction B
    ON A.OSD = B.fld_ActionID
WHERE B.fld_ActionID IN (100, 200, 360, 454, 457)

我希望将单词B.fld_ActionName从和转换为如下

New         (still the same no change)
Checked     (still the same no change)
For Recall -->recall
EL -->indexed EL
Watch -->Scrap watch

可能吗?如果是,那怎么办?我真的不知道 case 是否适用于此,我是 TSQL 新手,我不知道如何实现它。

谢谢

4

2 回答 2

2
SELECT 
    CASE
        WHEN B.fld_ActionName IN ('New','Checked') THEN B.fld_ActionName
        WHEN B.fld_ActionName 'For Recall' THEN 'recall'
        WHEN B.fld_ActionName 'EL' THEN 'indexed EL'
        WHEN B.fld_ActionName 'Watch' THEN 'Scrap watch'
    END,
    ISNULL(A.COUNT,0) count,
    ISNULL(A.GRAMS,0) grams,
    ISNULL(A.PRINCIPAL,0) principal
FROM #PULLEDOUT A
     RIGHT JOIN Reference.tbl_RefAction B
         ON A.OSD =B.fld_ActionID
WHERE B.fld_ActionID in (100,200,360,454,457)
于 2013-10-09T08:49:06.813 回答
1

尝试这个:

SELECT
  CASE b.fld_ActionName
   WHEN 'For Recall' THEN 'recall'
   WHEN 'EL' THEN 'indexed EL'
   WHEN 'Watch' THEN 'Scrap watch'
   ELSE b.fld_ActionName 
  END AS 'Action',
  ISNULL(A.COUNT,0) AS 'count',
  ISNULL(A.GRAMS,0) AS 'grams',
  ISNULL(A.PRINCIPAL,0) AS 'principal' 
FROM #PULLEDOUT A
RIGHT JOIN Reference.tbl_RefAction B
ON A.OSD =B.fld_ActionID
WHERE B.fld_ActionID in (100,200,360,454,457)
于 2013-10-09T08:51:33.447 回答