By the way, if you want to display values without time portion, you should use the date data type, not datetime. A date time cannot ever show as a blank. It is either a NULL or a valid date time. If you attempt to set it to a blank, you get as you know To be able to show a blank, you must convert the datetime to a string type.
That will give you yyyy-mm-dd. You can use the size of 10 along with style to return iso format without the time portion like so:. You can find the other style codes for convert here: docs: cast and convert. You could use coalesce.
A column must always have one type regardless of row, so you have to convert your date type to a text type before you pass it to coalesce:.
How are we doing? Please help us improve Stack Overflow. Take our short survey. Stack Overflow for Teams — Collaborate and share knowledge with a private group.
Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 4 years, 4 months ago. Active 4 years, 4 months ago. Well, you are partially right but there are some is another step that has to happen first. By default DateTime is not nullable because it is a Value Type, using the nullable operator introduced in C 2, you can achieve this. You wont be able to achieve this unless you convert datatype to varchar or char.
Reason is '' is not a valid datetime value. So '' will interpreted as value of 0 which corresponds to a datevalue of If this is for display purpose I would suggest keeping the datatype as is and store value as base date Then in your presentation layer you can apply logic to replace the base date with blank.
Doing data conversion just for this requirement in sql will mean the field losing its original datatype which will cause issues if these values are used for any further manipulation like comparison,sorting etc. Active 2 years ago. Viewed 77k times. I am using SQL Server. Improve this question. Reeya Oberoi Reeya Oberoi 2 2 gold badges 15 15 silver badges 36 36 bronze badges.
This may put you on the right track. You can convert the Datetime to a string since datetime cannot return an empty value. Add a comment. Active Oldest Votes. You can avoid having this sql server default value by doing something like this.
Improve this answer.
0コメント