当值为0.00时,如何在money列中插入' - '

时间:2015-10-29 20:49:46

标签: sql-server

如果在结果集中值为'-'时如何插入0.00,则水晶报表中的摘要不起作用?

Create Table #Results
(
    TerminalNumber       INT,
    ContractNumber       VARCHAR(50),
    CustomerName  VARCHAR(80),
    TotalDeficiency NUMERIC(13,2),
    TotalIncremental NUMERIC(13,2),
    MonthPeriod VARCHAR(20)
)




SELECT TerminalNumber
      ,ContractNumber
      ,CustomerName
      ,CASE WHEN TotalDeficiency = 0.00 THEN '-' ELSE CAST(TotalDeficiency AS NUMERIC(13,2)) END AS TotalDeficiency 
      ,CASE WHEN TotalIncremental = 0.00 THEN '-' ELSE CAST(TotalIncremental AS NUMERIC(13,2)) END AS TotalIncremental 
      ,MonthPeriod
      ,CONVERT(VARCHAR(10), @billing_date, 101) 'BillingDate' 
      FROM #Results order by CustomerName

1 个答案:

答案 0 :(得分:4)

如果您在演示文稿中需要,可以使用CASE

SELECT 
   CASE 
    WHEN TotalDeficiency = 0.00 THEN '-' 
    ELSE CAST(TotalDeficiency AS VARCHAR(10))
   END AS TotalDeficiency
FROM #Results;
如果使用IIF

,请

SQL Server 2012+

SELECT
  IIF(TotalDeficiency = 0.00, '-', CAST(TotalDeficiency AS VARCHAR(10)) ) 
  AS TotalDeficiency 
FROM #Results;

LiveDemo

但您无法在-列中插入字符MONEY