Tsql using, for example, a wildcard and a finite space?

I can not get a similar operator to work with a space and complete the template. My request is as follows:

select * from Table where Field like 'Desc_%'

Data is separated by spaces, such as Desc Top, Desc Bottom, etc. The query works when I use the "Desc_%" pattern, but not when I use the "Desc%" pattern. Nvarchar field (255).

Any ideas?

EDIT

It turns out that the data was split into tabs, and when I copied the value from 2008 Management Studio, it converted the tab to a space. Invalid error. I liked the tip [], so I designated it as the answer. Thanks to everyone, I will remember that I do not trust the copies from the grid results.

+5
source share
3 answers

Use the brackets '[' and ']' to configure the one-character class to match. In your case, SQL should look like this: "select * from the table where the field is" Desc []% '"

EDIT: add sample, link

CREATE TABLE #findtest (mytext  varchar(200) )

insert #findtest VALUES ('Desc r')
insert #findtest VALUES ('Descr')

select * from #findtest where mytext like 'Desc[ ]%'

DROP TABLE #findtest

(1 row(s) affected)

(1 row(s) affected)
mytext
--------
Desc r

(1 row(s) affected)

See this .

+3
source

Since the underscore is a single-character pattern, and the percentage is the wildcard multi-char, they are the same ("%" and "_%"). It is as if you were asking for two consecutive wildcards. I'm not sure that I understand your question, but I'm not surprised that it does not behave the way you expect.

0
source

, , ASCII?

SELECT * FROM Table WHERE Field Like 'Desc' + CHAR(32) + '%'
0

All Articles