Incorrect syntax near the keyword 'WHERE'. mssql - typeorm

Issue Description

When joining many-to-many I receive the following error: Incorrect syntax near the keyword 'WHERE'

Expected Behavior

Exception should not be thrown and query should be generated correctly.

Actual Behavior

Query is generated incorrect using QueryBuilder.

SELECT "tag"."id" AS "tag_id", "tag"."name" AS "tag_name", "event"."imageUrl" AS "event_imageUrl", "event"."id" AS "event_id", "event"."title" AS "event_title", "event"."isMainEvent" AS "event_isMainEvent", "event"."Host_id" AS "event_Host_id", "event"."ParentEvent_id" AS "event_ParentEvent_id" FROM "tag" "tag" INNER JOIN "event" "event" WHERE = @0 -- PARAMETERS: 

As you can see the join ... ON ... is missing.

Steps to Reproduce

const test = this.createQueryBuilder('tag')
            .innerJoinAndSelect(Event, 'event')
            .where(' = :eventName', { eventName: 'a' })

My Environment

Dependency Version
Operating System Windows 10
TypeORM version v0.2.32

Relevant Database Driver(s)

  • [ ] aurora-data-api
  • [ ] aurora-data-api-pg
  • [ ] better-sqlite3
  • [ ] cockroachdb
  • [ ] cordova
  • [ ] expo
  • [ ] mongodb
  • [ ] mysql
  • [ ] nativescript
  • [ ] oracle
  • [ ] postgres
  • [ ] react-native
  • [ ] sap
  • [ ] sqlite
  • [ ] sqlite-abstract
  • [ ] sqljs
  • [x ] sqlserver

Are you willing to resolve this issue by submitting a Pull Request?

  • [ ] Yes, I have the time, and I know how to start.
  • [ ] Yes, I have the time, but I don't know how to start. I would need guidance.
  • [ ] No, I don't have the time, although I believe I could do it if I had the time...
  • [x] No, I don't have the time and I wouldn't even know how to start.
Asked Oct 02 '21 16:10
avatar ghost

2 Answer:

I think it's good that you put the source of the entities too.

Answered May 07 '21 at 11:36
avatar  of v1d3rm3

When opening an issue, people will be better able to provide help if you provide code that they can easily understand and use to reproduce the problem. This boils down to ensuring your code that reproduces the problem follows the following guidelines:

  • Minimal – Use as little code as possible that still produces the same problem
  • Complete – Provide all parts someone else needs to reproduce your problem in the question itself
  • Reproducible – Test the code you're about to provide to make sure it reproduces the problem


The more code there is to go through, the less likely people can find your problem. Streamline your example in one of two ways:

  1. Restart from scratch. Create a new program, adding in only what is needed to see the problem. Use simple, descriptive names for functions and variables – don’t copy the names you’re using in your existing code.
  2. Divide and conquer. If you’re not sure what the source of the problem is, start removing code a bit at a time until the problem disappears – then add the last part back.

Don't sacrifice clarity for brevity when creating a minimal example. Use consistent naming and indentation, and include code comments if needed. Use your code editor’s shortcut for formatting code.

Don't include any passwords or credentials that must be kept secret.


Make sure all information necessary to reproduce the problem is included in the issue itself.

If the problem requires some code as well as some XML-based configuration, include code for both. The problem might not be in the code that you think it is in.

Use individual code blocks for each file or snippet you include. Provide a description for the purpose of each block.

DO NOT use images of code. Copy the actual text from your code editor, paste it into the issus, then format it as code. This helps others more easily read and test your code.


To help you solve your problem, others will need to verify that it exists.

Describe the problem. "It doesn't work" isn't descriptive enough to help people understand your problem. Instead, tell other readers what the expected behavior should be. Tell other readers what the exact wording of the error message is, and which line of code is producing it. Use a brief but descriptive summary of your problem as the title of your question.

Eliminate any issues that aren't relevant to the problem. If your question isn’t about a compiler error, ensure that there are no compile-time errors.

Double-check that your example reproduces the problem! If you inadvertently fixed the problem while composing the example but didn't test it again, you'd want to know that before asking someone else to help.

Answered Jun 21 '21 at 06:43
avatar  of imnotjames