locked
Numeric Value RRS feed

  • Question

  • User-797751191 posted

    Hi

       I have numeric field which has null value . I want to display it as - hyphen in report

    Thanks

    Sunday, March 1, 2020 8:48 AM

All replies

  • User475983607 posted

    Use COALESCE or ISNULL.

    https://docs.microsoft.com/en-us/sql/t-sql/language-elements/coalesce-transact-sql?view=sql-server-ver15

    https://docs.microsoft.com/en-us/sql/t-sql/functions/isnull-transact-sql?view=sql-server-ver15

    CREATE TABLE #TempNums (Num INT NULL)
    
    INSERT INTO #TempNums (Num)
    VALUES(1), (null), (2), (null)
    
    SELECT * FROM  #TempNums
    
    SELECT COALESCE(CAST(num AS VARCHAR(10)), '-')
    FROM #TempNums

    jsshivalik, COALESCE or ISNULL is not hidden or hard to find.  IMHO, you've been on these forums long enough to use google and read the official documentation.  

    Sunday, March 1, 2020 3:25 PM
  • User-1716253493 posted

    For gridview column, there is null display

     <asp:BoundField NullDisplayText="-" />

    I guess, there is similar way for others

    Monday, March 2, 2020 12:43 AM
  • User288213138 posted

    Hi jsshivalik,

    I have numeric field which has null value . I want to display it as - hyphen in report

    Can you describe the problem you encountered in detail?

    The numeric field which has null value in the asp.net or sql report?

    Can you show me your code?

    Best regards,

    Sam

    Monday, March 2, 2020 3:50 AM
  • User-797751191 posted

    Hi Samwu

      In Sql query

    Thanks

    Tuesday, March 3, 2020 1:41 PM
  • User-1716253493 posted

    There is no "-" value in numeric, you need to convert it to varchar first

    SELECT ISNULL(CONVERT(varchar, colomn1), '-') AS display
    FROM Table_1

    Wednesday, March 4, 2020 12:28 AM