数据类型转换

boytcl 2003-11-11 03:44:54
如何将char or varchar type 转换成int or float or real or numeric
反正只要把char 型转换成可以用 sum,avg等函数的数据类型就行了,多谢指教!
...全文
26 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
boytcl 2003-11-12
  • 打赏
  • 举报
回复
谢谢大家,应该是字段的问题,因为那字段不能转成其他的数据类型
那怎样才能让他转呢?
zjcxc 元老 2003-11-11
  • 打赏
  • 举报
回复
如果你不能确定表中的字段能否转换为数字型,请改用:

case when isnumeric(字段)=1 then cast(字段 as float) else 0 end
wzh1215 2003-11-11
  • 打赏
  • 举报
回复
cast
convert
zjcxc 元老 2003-11-11
  • 打赏
  • 举报
回复
cast(字段 as int)

cast(字段 as float)

cast(字段 as real)

cast(字段 as numeric(20,2))
ghostzxp 2003-11-11
  • 打赏
  • 举报
回复
cast(字段 as real)
txlicenhe 2003-11-11
  • 打赏
  • 举报
回复
cast('123' as int)
convert(int,'1234')

34,593

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧