Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

LIKE % value % issue #35

Open
pebanfield opened this Issue Apr 5, 2013 · 1 comment

Comments

Projects
None yet
1 participant

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment