对日期格式的查询

对日期格式的模糊查询:
   需要借助convent 函数将一种数据类型的表达式转换为另一种数据类型的表达式,

直接进行查询的时候都可以查询出但是  1 不起左右,,使用2019_01的话查不出来

select * from dbo.tbmdKaoQingInfo where YearMonth like '%2019_1%'    

select * from dbo.tbmdKaoQingInfo where YearMonth like '%2019%'

如下图:

这也不行

select * from dbo.tbmdKaoQingInfo where YearMonth like '%2019-1%'

也不行

select * from dbo.tbmdKaoQingInfo where YearMonth like '%2019-01%'

扫描二维码关注公众号,回复: 7022357 查看本文章

建议使用  convert  进行转化一下,年月日就都有用了

CAST 和 CONVERT

将某种数据类型的表达式显式转换为另一种数据类型。CAST 和 CONVERT 提供相似的功能。

使用 CAST:CAST ( expression AS data_type )

使用 CONVERT:CONVERT (data_type[(length)], expression [, style])

select * from dbo.tbmdKaoQingInfo where CONVERT(varchar,YearMonth,120) like '%2019-01%'

日期格式样式,借以将 datetime 或 smalldatetime 数据转换为字符数据(nchar、nvarchar、char、varchar、nchar 或 nvarchar 数据类型);或者字符串格式样式,借以将 float、real、money 或 smallmoney 数据转换为字符数据(nchar、nvarchar、char、varchar、nchar 或 nvarchar 数据类型)。

SQL Server 支持使用科威特算法的阿拉伯样式中的数据格式。

在表中,左侧的两列表示将 datetime 或 smalldatetime 转换为字符数据的 style 值。给 style 值加 100,可获得包括世纪数位的四位年份 (yyyy)。

dfd

猜你喜欢

转载自www.cnblogs.com/obge/p/11353607.html
今日推荐