How can I make SQL Server return FALSE for comparing varchars with and without trailing spaces?

后端 未结 6 633
刺人心
刺人心 2020-12-10 12:55

If I deliberately store trailing spaces in a VARCHAR column, how can I force SQL Server to see the data as mismatch?

SELECT \'foo\' WHERE \'bar\         


        
6条回答
  •  [愿得一人]
    2020-12-10 13:37

    I've only really got two suggestions. One would be to revisit the design that requires you to store trailing spaces - they're always a pain to deal with in SQL.

    The second (given your SARG-able comments) would be to add acomputed column to the table that stores the length, and add this column to appropriate indexes. That way, at least, the length comparison should be SARG-able.

提交回复
热议问题