SQL Server datetime LIKE select?

后端 未结 11 1801
别那么骄傲
别那么骄傲 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 02:56

    If you do that, you are forcing it to do a string conversion. It would be better to build a start/end date range, and use:

    declare @start datetime, @end datetime
    select @start = '2009-10-10', @end = '2009-11-10'
    select * from record where register_date >= @start
               and register_date < @end
    

    This will allow it to use the index (if there is one on register_date), rather than a table scan.

提交回复
热议问题