记录一些mysql函数修改为sqlserver的写法,date_format,find_in_set等

1,date_format

参数格式2018-08-30 2018-09-10

mysql: 

between DATE_FORMAT(left(#{time},10),'%Y-%c-%d 00:00:00' ) and DATE_FORMAT(right(#{time},10),'%Y-%c-%d 23:59:59' )

sqlserver:

between CONVERT(varchar(100),left(#{time},10),20) and CONVERT(varchar(100),right(#{time},10),20)
mysql:

date_format(a.time, '%Y/%c/%d %h:%i:%s' )

sqlserver

convert(varchar(100),a.time,20)

convert 第三个参数20表示格式为%Y/%c/%d %h:%i:%s,若为10则表示%Y/%c/%d

2,find_in_set

mysql:

FIND_IN_SET(a.flag,#{flag})

mysql参数格式为"0,1,2,3,5,11,99",并且是精确匹配,使用很方便
sqlserver:

mapper.xml 中的sql写法如下:
b.flag in
   
        #{flag}
   

参数格式:
int[] flag= new int[]{1,2,3,11,22,33,99};
封装到map中传递到mapper中

3,concat

mysql:

拼接like查询

CONCAT(CONCAT('%',#{key},'%'))

参数为key

sqlserver:

like查询

'%'+#{key}+'%'

4,date_add

mysql:

date_add(now(),interval 5 day)

mysql的当前时间为now();

sqlserver:

dateadd(day,5,getdate())

sqlserver的当前时间为getdate();

 

你可能感兴趣的:(mysql,sqlserver)