Home  /  Questions  /  Question

67   95.8
Sep 12, 2013

An example please on how to use a SQL LIKE in Spark 4.5 Platform

Can you guys show an example on how to perform a LIKE query in the where parameter?

I tried this:

where: "productid like '%@0%' param: "014"

I got back 0 rows.

Running this in TSQL in SQL management studio did yield back some rows

What should be the correct way to do this in Spark 4.5?

508   99.9
Sep 12, 2013
Hello Parity Bit: 

The Art Shop has a example (where you search for products) that demonstrates the use of a SQL LIKE.
You'll find it in the Products action method in the ProductController.

I think where you got confused is the placement of the '%'.
It should be placed on the value, rather than the parameter, something like this:  

var products = db.Products.All( where: "ProductId LIKE @0", parms: "%014%" );

Hope this helps.