Friday, February 24, 2012

blank spaces....

select * from Customer where customerId ='123 '
select * from Customer where customerId ='123'
Both the above queries return the same result.
What is the property which ignores the white space character?
SQL 2K.
Thank you,
Larry
Larry Smith wrote:
> select * from Customer where customerId ='123 '
> select * from Customer where customerId ='123'
> Both the above queries return the same result.
> What is the property which ignores the white space character?
> SQL 2K.
> Thank you,
> Larry
Assuming you really have blank spaces in your customerId column, you can
use a LIKE clause to force the search for a trailing blank.
create table #whitespacetest (col1 varchar(10))
insert into #whitespacetest values ('ABC')
insert into #whitespacetest values ('ABC ')
select col1, col1 + '1' from #whitespacetest
select col1 from #whitespacetest where col1 = 'ABC'
select col1 from #whitespacetest where col1 = 'ABC '
select col1 from #whitespacetest where col1 LIKE 'ABC'
select col1 from #whitespacetest where col1 LIKE 'ABC[ ]'
drop table #whitespacetest
David Gugick
Quest Software
www.imceda.com
www.quest.com

No comments:

Post a Comment