Query on the date format

 

Fuzzy queries on the date format:
   needs the convent function to convert a data type of expression to another data type of expression,

When direct query can check out all but about 1 ,, can not afford to use 2019_01, then check it out

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

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

As shown below:

This does not work

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

Does not work

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

Recommended convert transformed it, date it has spent

CAST and CONVERT

The expression of some explicit data type into another data type. CAST and CONVERT provide similar functionality.

使用 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%'

Date format model, whereby the datetime smalldatetime data or character data (nchar, nvarchar, char, varchar, nchar or nvarchar data type); string format or style, whereby the float, real, money or data to character data smallmoney (nchar, nvarchar, char, varchar, nchar or nvarchar data type).

SQL Server supports the use of data format Arab style algorithm in Kuwait.

In the table, the left side shows a two datetime or smalldatetime style value is converted into character data. To the style value plus 100, including the availability of digital century four-digit year (yyyy).

 

 

 

 

dfd

Guess you like

Origin www.cnblogs.com/obge/p/11353607.html