Set default value in column IF condition is met in SQL 2008

这一生的挚爱 提交于 2019-12-08 12:55:33

Yes, you can set up a default value, but you want the syntax to be correct:

[date] datetime default (case when datepart(hh, getdate()) = 24 then getdate() - 1 else getdate() end)

However, I don't think you should have a datetime value in a field called "date". How about:

AsOfDate date default (case when datepart(hh, getdate()) = 24 then cast(getdate() - 1 as date) else cast(getdate() as date) end)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!