想将sql server 中的getdate函数转换成yyyy-mm-dd格式,如下:select cast(cast(getdate() as varchar(10)) as datetime),出错提示The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
好像跟sp_configure 'default language'中的default language有关系。
为了不让与sql server 语言环境相关联,使用另外一种方式:select cast(convert(varchar(10), getdate(), 120) as datetime)
好像跟sp_configure 'default language'中的default language有关系。
为了不让与sql server 语言环境相关联,使用另外一种方式:select cast(convert(varchar(10), getdate(), 120) as datetime)
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/16582684/viewspace-741694/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/16582684/viewspace-741694/
本文解决在SQL Server中将getdate()函数转换为yyyy-mm-dd格式时出现的问题,通过使用convert(varchar, getdate(), 120)避免了错误提示,并提供了解决方案。
2万+

被折叠的 条评论
为什么被折叠?



