SQL Server datetime LIKE select?

后端 未结 11 1825
别那么骄傲
别那么骄傲 2020-11-28 02:44

in MySQL

select * from record where register_date like \'2009-10-10%\'

What is the syntax in SQL Server?

11条回答
  •  青春惊慌失措
    2020-11-28 03:14

    There's no direct support for LIKE operator against DATETIME variables, but you can always cast the DATETIME to a VARCHAR:

    SELECT (list of fields) FROM YourTable
    WHERE CONVERT(VARCHAR(25), register_date, 126) LIKE '2009-10-10%'
    

    Check the MSDN docs for a complete list of available "styles" in the CONVERT function.

    Marc

提交回复
热议问题