Reputation: 1722
Good day everyone, I have this query:
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)
I want the words on B.fld_ActionName
to be transformed from and to as follows
New (still the same no change)
Checked (still the same no change)
For Recall -->recall
EL -->indexed EL
Watch -->Scrap watch
Is it possible? If yes then how? I really do not know if case is applicable to this, I'm new to TSQL and i do not know how to implement it.
Thank you
Upvotes: 0
Views: 474
Reputation: 525
Try this:
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)
Upvotes: 1
Reputation: 18411
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)
Upvotes: 2