question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can I dynamically create a query???

See original GitHub issue

I need to build my query with a forEach loop, then pass to sql.query(query) but it’s not working. Any help?? If not possible with this package, can you point me in a direction where it is?

ie:

query = 'select id, name, ';

forEach(product => query += 'sum(case when ....);

query += 'from items where ...';

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
willmorgancommented, Oct 18, 2018

That is valid, too. But from OP’s post it looked like some fairly low level but simplistic CRUD usage. You can use knex and this library together which, from OP’s post, I concluded would probably be better.

I’m on a bit of a tidying spree and trying to weed out bugs from “how do I do X”/general SQL questions/my environment config is wrong/poor bug reports, so apologies my first response wasn’t drafted with 100% nuance 🙂

0reactions
willmorgancommented, Oct 18, 2018

No worries. Initial response updated.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Learn SQL: Dynamic SQL - SQLShack
Dynamic SQL is a programming technique you can use to build SQL statements as textual strings and execute them later.
Read more >
Dynamic SQL Tutorial - Introduction, Examples and Query
How to use Dynamic SQL? · -- Start by declaring the Query variable and other required variables · DECLARE @SQL · DECLARE @variable1...
Read more >
How to dynamically generate SQL query based on user's ...
I need to create a GUI, using which users can select several attributes which will be used to query the database to find...
Read more >
Dynamic SQL in SQL Server - TutorialsTeacher
Dynamic SQL is a programming technique where you build SQL query as a string and execute it dynamically at runtime. It lets you...
Read more >
Build dynamic query with values from search form - Office
Sometimes, you may want to create a form that serves as a search form. You want to be able to enter values on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found