Groups | Blog | Home
all groups > sql server (microsoft) > july 2005 >

sql server (microsoft) : Can't SELECT a string value with spaces


tabladude NO[at]SPAM gmail.com
7/30/2005 7:21:24 PM
Hi:

I'm tearing my hair out with this!

I'm trying to do a simple SELECT:

select * from MyTable
WHERE MyField = 'This field value has spaces'

and it is coming up blank. If I look for any value without spaces, it
gives me records. The field is varchar(32), and I'm using SQL 2000 SP4.

Any ideas??

Thanks,
Kayda
dbmonitor
7/31/2005 4:08:57 PM

[quoted text, click to view]

Why don't you append a character to the end of each string
i.e.
select * from MyTable
WHERE MyField + '@' = 'This field value has spaces' + '@'

--
David Rowland
Version 1.3 of DBMonitor is out now!
http://dbplussoftware.com
louis
8/2/2005 5:04:17 PM
By default, varchar does not trim trailing spaces. You need to perform
ltrim(rtrim()) when the data is entered. You can play with Like and
other tricks. However, when you have a large table, you want to be
able to index the table as is.
naka55n NO[at]SPAM hotmail.com
8/3/2005 7:01:23 AM
Can you post the DDL and the DML so we can replicate the problem?

Not knowing if this was correct or not this is what I did:

CREATE TABLE TempSaiko1 (
SField1 VARCHAR(50),
SField2 VARCHAR(10)
)

INSERT INTO TempSaiko1 VALUES('Test Data',' ')

SELECT * FROM TempSaiko1 WHERE SField2 = ' '

SField1 SField2
-------------------------------------------------- ----------
Test Data

(1 row(s) affected)
AddThis Social Bookmark Button