Question

From my experience it seems that select where like on data from my database doesnt work on fields in nchar format but does in nvarchar format. Is this true?

If so why and is changing the data type to nvarchar the only work around?

I have noticed that nchar is of ANSIString type and nvarchar is just String but that seems odd that one works and the other doesnt when they're both unicode.

Was it helpful?

Solution

Turns out you were all pretty much on the money, it is a padding related issue an nchar or char has one space to right of it as padding which means I'd have to do something like this

SELECT * FROM foo WHERE bar LIKE '%bb %'

Instead of this

SELECT * FROM foo WHERE bar LIKE '%' + @field + '%'

This works the other way round to the latter query will select all fields that are nvarchar etc. but wont select fields that are nchar or char.

(EDIT)

SELECT * FROM foo WHERE bar LIKE '%bb%'

This solution will work on both sets of data types I have mentioned. No space needed after the bb

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top