Sql query RRS feed

  • Question

  • User-797751191 posted


      I have below Sql query i want if posting Date is null then - should be displayed

    string sql = @"select A.[Invoice No] as InvoiceNo, A.[Posting Date] as PostingDate,
                from [test] as A


    Wednesday, July 17, 2019 9:04 AM

All replies

  • User753101303 posted


    I would handle that rather at the UI level using for example using : https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.dataannotations.displayformatattribute.nulldisplaytext?view=netframework-4.8

    If doing that at the SQL level then you'll return a string value rather than a date value to your C# code which could cause issues depending on what you'll do later...

    Wednesday, July 17, 2019 9:39 AM
  • User-719153870 posted

    Hi jsshivalik,

    If you want to replace a null value with'-', I recommend that you use the isnull(convert(varchar(50),A.UDate),'-') method to convert date type to varchar type and then replace null value with ‘-’.

    Please refer to below codes:

    select isnull(convert(varchar(50),A.UDate),'-') as Date,A.UAge as Age from Users as A

    Here's result of this sql query:

    Best Regard,

    Yang Shen

    Thursday, July 18, 2019 1:27 AM