August 15, 2006 at 11:56 am
SELECT * from TAB_A WHERE COL_1='SMITH'
SELECT * from TAB_A WHERE COL_1='SMITH ' --- note the 5 spaces after COL_1 name value 'Smith'
The column values 'SMITH' and 'SMITH ' are both returning the same set of 3 qualified rows. (I checked the PK values)
Is there a SQL setting I am missing here? ANSI_NULLS ?? If so, what command can I use to alleviate the duplicate result sets? 'SMITH' does NOT equal 'SMITH '
thx in advance
August 15, 2006 at 12:19 pm
It's due to ANSI SQL standards.
Does this help:
http://support.microsoft.com/default.aspx?scid=kb;en-us;316626
You can work around it using LIKE:
SELECT * from TAB_A WHERE COL_1 LIKE 'SMITH'
SELECT * from TAB_A WHERE COL_1 LIKE 'SMITH ' --- note the 5 spaces after COL_1 name value 'Smith'
August 15, 2006 at 1:01 pm
if you do not know the value ahead of time, you can make sure that things don't have trailing spaces by comparing the datalength.
where col1 = col2 and datalength(col1) = datalength(col2)
Changing the ANSI settings for your stored procedure will eliminate the 'non-consideration of trailing whitespace' problem, but if you can't change that, you will have to use the datalength hack.
August 15, 2006 at 7:57 pm
Why do you have trailing spaces and what is it that you're trying to do? Are you trying to find entries that have trailing spaces to eliminate the trailing spaces or ????
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply