Simon Verbeke
Simon Verbeke

Reputation: 3005

SQL Server CE wildcards

My database has a products table. This contains a column called layers. That column contains data in the form of 0102, where 01 is the closet and 02 is the layer in that closet.

I need to query my database for closets as well (not only layers). How do I use wildcards, so that I can query for all products in - for example - closet 01, 02 and 03?

This is what I have now, but it isn't working:

SELECT Artikelnummer, Omschrijving, Legger, Voorraad 
FROM Artikels 
WHERE Legger LIKE 01* OR  Legger LIKE 02* OR  Legger LIKE 03*  
ORDER BY Artikelnummer

(Sorry for the dutch names)

Upvotes: 1

Views: 353

Answers (1)

marc_s
marc_s

Reputation: 754488

SQL Server T-SQL uses the % as the wildcard for "any characters (and _ for one character, any character - equivalent to ? in Windows/DOS), any numbre thereof" - and you also need to put your string literals into single quotes - so use:

SELECT Artikelnummer, Omschrijving, Legger, Voorraad 
FROM Artikels 
WHERE Legger LIKE '01%' OR  Legger LIKE '02%' OR  Legger LIKE '03%'
ORDER BY Artikelnummer

Upvotes: 2

Related Questions