SQL Server Column that outputs a number but I am trying to have it output a name depending on what number it is

cbeh67ev  于 2023-10-15  发布在  其他
关注(0)|答案(1)|浏览(84)

I am trying to place a column next to CREATEDATBRANCH that shows a name instead of a number. How can I do that?

This is my SQL query so far:

SELECT [PARENTACCOUNT]
  ,[ID]
  ,[TYPE]
  ,[ORIGINALDATE]
  ,[OPENDATE]
  ,[CHARGEOFFDATE]
  ,[CLOSEDATE]
  ,[PURPOSECODE]
  ,BALANCE AS 'Current Balance'  
  ,[ORIGINALBALANCE]
  ,[CHARGEOFFTYPE]
  ,[CHARGEOFFAMOUNT]
  ,[DESCRIPTION]
  ,[MATURITYDATE]
  ,[BRANCH]
  ,[CREATEDBYUSER]
  ,[CREATEDATBRANCH]
FROM 
    [dbo].[LOAN]
WHERE
    OPENDATE BETWEEN '2023-09-01' AND '2023-09-30' 
    AND CLOSEDATE IS NULL;

I tried to use this code but it does not include it in my query, instead it creates it as another result.

SELECT
    CREATEDATBRANCH,
    CASE
        WHEN CREATEDATBRANCH = 0 THEN 'Special'
        ELSE CAST(LOAN.CREATEDATBRANCH AS varchar(4))
    END AS 'Location'
FROM
    LOAN;
6ljaweal

6ljaweal1#

Take just the CASE expression from the second query and include it at the end of the SELECT list in the first query.

But really, I'd leave this adjustment for client code or the reporting tool.

相关问题