Hi
In a query if value is 1900-01-01 00:00:00.000 then '' should be displayed.
Thanks
Hi
In a query if value is 1900-01-01 00:00:00.000 then '' should be displayed.
Thanks
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Nitin SontakkeRank #264 · 9.6K reputationPosted Aug 10, 2023, 12:11 AM EDT
The problem is not at the SQL Server end. You are unlikely to have this value stored in db.
Problem is this column is either null, or is of data type string and is empty. When such is the case, it gets translated as above value in C#.
So you will have to deal with this there!
Ramco RamcoRank #462 · 5.4K reputationPosted Aug 9, 2023, 11:21 PM EDT
Hi
I have written below code but it is showing NULL
case WHEN HRTST = '1900-01-01 00:00:00.000' THEN '' end
Thanks
Mohammad HussainRank #513 · 4.8K reputationPosted Aug 9, 2023, 8:10 AM EDT
SELECT CASE WHEN YourDateColumn = '1900-01-01 00:00:00.000' THEN '' ELSE CONVERT(VARCHAR, YourDateColumn, 120) -- Display the date in a different format if it's not '1900-01-01' END AS FormattedDate FROM YourTable;Cr BhargaviRank #420 · 5.9K reputationPosted Aug 10, 2023, 7:40 AM EDT
SELECT CASE WHEN YourDateColumn = '1900-01-01 00:00:00.000' THEN '' ELSE CONVERT(VARCHAR, YourDateColumn, 120) -- Convert date to desired format END AS FormattedDate FROM YourTable;Saravanan GanesanRank #153 · 15.1K reputationPosted Aug 16, 2023, 6:15 AM EDT
To display an empty string (
'') when the value in a query is1900-01-01 00:00:00.000, you can use theCASEstatement to conditionally format the output. Here's an example of how you can achieve this:SELECT CASE WHEN YourColumn = '1900-01-01 00:00:00.000' THEN '' ELSE CONVERT(VARCHAR, YourColumn, 120) -- Convert to desired date format if needed END AS FormattedColumn FROM YourTable;Replace
YourColumnwith the actual name of the column in your table andYourTablewith the actual name of the table. This query uses theCASEstatement to check if the value is'1900-01-01 00:00:00.000'and replaces it with an empty string. If the value is different, you can use theCONVERTfunction to format it as needed (in this case, it's converted to the ISO 8601 format with the style code120).Tahir AnsariRank #366 · 6.8K reputationPosted Aug 9, 2023, 8:55 AM EDT
assume you have a table named
Orderswith a column namedOrderDate. You want to display an empty string when theOrderDateis '1900-01-01 00:00:00.000'.SELECT CASE WHEN OrderDate = '1900-01-01 00:00:00.000' THEN '' ELSE CONVERT(VARCHAR, OrderDate, 120) -- Formatting the date END AS FormattedOrderDate FROM Orders;Anandu G NathRank #681 · 3.5K reputationPosted Dec 20, 2023, 12:36 AM EST
SELECT CASE WHEN Added_Date= '1900-01-01 00:00:00.000' THEN '' ELSE CONVERT(VARCHAR, Added_Date, 120) -- Display the date in a specific format if it's not '1900-01-01 00:00:00.000' END AS FormattedDate FROM Employee;