SQLSERVER--函数集锦

来源:互联网 发布:ftp怎么上传源码 编辑:程序博客网 时间:2024/05/29 04:35

1.给表添加一列

 

select *,'sqlserver' as 'Source' from Table A

 

sqlserver为增加列的内容,Source为增加列的名称

 

2.字符在字符窜中的位置:CharIndex(寻找的字符,内容)


select CHARINDEX('ASD',ColA)  

返回 ‘ASD’中列ColA的位置,  如果ColA的内容为'qasdfghjkl',则返回 2

 

 

3.截取字符窜函数 Substring(列名,开始位置,长度) 

 

select substring('qasdfghjkl',charindex('asd','qasdfghjkl'),charindex('l','qasdfghjkl')-charindex('asd','qasdfghjkl'))

结果:返回 asdfghjk

4.判断函数:case when 表达式 THEN 值1 else 值2

select *,(case when enddate is not null then 'end' else 'notend' end) as isend

 from tblsetupjob order by createdate desc

5.getdate() 返回当前系统的时间

 

原创粉丝点击