系统函数
1.case when ... then ..else ..end(用于对条件进行测试)
e.Select id,case when name='deepwishly' then '老大' else '其他' end as Type
显示 id type
1 老大
2.cast()/convert() 前者具有ANSI SQL-92兼容性,后者功能更强大
e, cast(variable_or_column As datatype);convert(datatype,varialbe_or_column)
3.isdate()判断是否是有效的日期或时间,测试日期格式必须与使用 set dateformat or set language设定的格式具有相同的地域格式
e, select isdate(varialbe_or_column)//是有效日期返回1否则返回0
4.isnull() 判断是否是null
isnull(value_to_test,new_value)
e,替换数据库或变量中null为某值,select isnull(variable_or_column,new_value)
5.isnumeric()判断是否是数字 返回0,false或1,true
e,select(variable_or_colunn)
本文介绍了SQL中的几个常用函数,包括用于条件判断的CASE WHEN...THEN...ELSE...END、转换类型的CAST()与CONVERT()、判断日期有效性的ISDATE()、处理NULL值的ISNULL()以及检查数字的ISNUMERIC()等。这些函数对于日常的数据处理和查询非常实用。
431

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



