zoukankan      html  css  js  c++  java
  • sqlserver------对日期格式的查询

    对日期格式的模糊查询:
       需要借助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%'

    建议使用  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

  • 相关阅读:
    反射
    关于EwebEeditor 不能上传图片问题解决方法
    js去掉前后空格
    园子开张
    使用Python 爬取 京东 ,淘宝。 商品详情页的数据。(避开了反爬虫机制)
    c#对于加密的一点整合 (AES,RSA,MD5,SHA256)
    移动战略调查:应用开发者首选微软Windows
    Surface Pro打包微软精华 今晚在华开售
    Ceph学习全过程 基于N版
    k8s中部署wordpress
  • 原文地址:https://www.cnblogs.com/obge/p/11353607.html
Copyright © 2011-2022 走看看