Last post Jul 18, 2019 01:27 AM by Yang Shen
Jul 17, 2019 09:04 AM|jsshivalik|LINK
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
Jul 17, 2019 09:39 AM|PatriceSc|LINK
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...
Jul 18, 2019 01:27 AM|Yang Shen|LINK
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: