node-tds icon indicating copy to clipboard operation
node-tds copied to clipboard

LIKE % value % issue

Open pebanfield opened this issue 12 years ago • 1 comments

I'm trying to use LIKE with WHERE, but I've not gotten it to work so far. My code is something like -

var term = req.query["term"]; queryStr = 'DECLARE @Param1 Int; SELECT TOP 5 CostCenter value, CostCenterDesc about, LOB lob FROM ServerServiceCostCenters '; queryStr += 'WHERE CostCenter LIKE @Param1';

var statement = conn.createStatement(queryStr); statement.execute({Param1: "%" + term + "%"});

This works when I remove the WHERE/LIKE part of the expression. Does this lib support using LIKE? Can you provide a quick code snippet?

Cool module. Nice job. Thanks!

Peter

pebanfield avatar Apr 05 '13 06:04 pebanfield

I've resolved my issue. There is no issue with the lib.

The problem was that I did not actually need to parameterize the LIKE match expression. I was simply missing some single quotes around the expression. I've modified my query like so -

queryStr = 'SELECT TOP 5 CostCenter value, CostCenterDesc about, LOB lob FROM ServerServiceCostCenters'; queryStr += "WHERE CostCenter LIKE '%" + term + "%'";

and now it works.

pebanfield avatar Apr 05 '13 16:04 pebanfield