Hi
I haveb below code in query . I want when count(*) = 0 then it should display it as '' but it is displaying 1901-01-01.
,case when(select count(*) from [PRQS].[dbo].[SentBackLog] where
and ModuleCode = T0.ModuleCode and EntryType = 'Submit') = 0 THEN CAST('' as datetime)
else (select top 1 EntryDate from [PRQS].[dbo].[SentBackLog] where
and ModuleCode = T0.ModuleCode and EntryType = 'Submit') End as 'Last Date'
FROM [EntryLog] T0
where T0.ModuleCode = 2
Thanks
Nitin SontakkePosted Nov 11, 2022, 1:28 PM
In case when ifTrue then ifFalse end, clause the data type of both ifTrue and ifFalse expression SHOULD be of the SAME data type.
In your case you are casting empty string to datetime, which defaults to 1-1.1901 by SQL Server. You can test this by a simple select statement - select cast('' as datetime).
Null is probably your best choice. Or otherwise make it string and 'No last date' and date as a string in the column.
Hope it clarifies.
Amit MohantyPosted Nov 11, 2022, 12:13 PM
Check this, it will return as NULL instade of '1900-01-01'
Vishal JoshiPosted Nov 11, 2022, 11:59 AM
Try this
Just Replace CAST('' as datetime) with ''
Ramco RamcoPosted Nov 11, 2022, 11:42 AM
Hi Amit
still not working. If no record return then what will be the value
Thanks
Amit MohantyPosted Nov 11, 2022, 10:40 AM
try this
Ramco RamcoPosted Nov 11, 2022, 10:27 AM
same issue
Amit MohantyPosted Nov 11, 2022, 10:16 AM
try this