问题描述
可能的重复:
t-sql cast vess vers convert
SQL中CAST和CONVERT之间的主要区别是什么原因导致两个执行数据类型转换?
推荐答案
铸造和转换具有相似的功能.转换是特定于SQL Server的,并且在日期和时间值,分数数字和货币指示符之间转换时允许更大的灵活性.铸件是两个函数中较大的ANSI标准.查看此博客以获取两种使用的示例: http://http://sqltutorials.blogspot.com/2007/06/sql-cast-and-convert.html
其他推荐答案
convert函数可以进行更复杂的转换,例如使用特定格式将datetime值转换为varchar:
convert(varchar(16), dateTimeValue, 120)
其他推荐答案
假设您在谈论SQL Server.
来自/MS187928.ASPX 和本文地址:https://www.itbaoku.cn/post/597707.html
问题描述
Possible Duplicate:
T-SQL Cast versus Convert
What is the major difference between CAST and CONVERT in SQL cause both performs data type conversion?
推荐答案
CAST and CONVERT have similar functionality. CONVERT is specific to SQL Server, and allows for a greater breadth of flexibility when converting between date and time values, fractional numbers, and monetary signifiers. CAST is the more ANSI-standard of the two functions. Check this blog for examples of using both of those: http://sqltutorials.blogspot.com/2007/06/sql-cast-and-convert.html
其他推荐答案
The convert function can do more complex conversions, for example converting a datetime value into varchar using a specific format:
convert(varchar(16), dateTimeValue, 120)
其他推荐答案
Assuming you're talking about SQL Server.
From http://msdn.microsoft.com/en-us/library/ms187928.aspx and http://msdn.microsoft.com/en-us/library/aa226054(v=sql.80).aspx
Explicitly converts an expression of one data type to another. CAST and CONVERT provide similar functionality.
So yes, they are functionally the same. They just have different syntax that allows for more complex conversions or (subjectively) improved readability.