简体   繁体   中英

Select Query is not working with WHERE clause when there is a space in column value

Select Query is not working with WHERE clause when there is a space in column value. since my table column value has space in it. When I copied same value from query result and put that with where clause, it doesn't return any result. .

select * from myTable

在此处输入图像描述

if I run below query

select * From myTable where OldLoanNumber ='000000010383904 '

, it doesn't return any result 在此处输入图像描述

SQL Server Version is 18.6 as shown in pic 在此处输入图像描述

Am I missing anything or any settings related to SQL Query Analyzer?

Use Ltrim, RTrim or Trim like for example

select * From myTable where Trim(OldLoanNumber) =Trim('000000010383904 ')

The ANSI standard says that string comparisons are to be padded to the same length, and I have observed that behavior many times.

I believe the most likely cause of your problem is the last character being a tab or other non space character that simply looks like a space to you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM