3

Getting errors in following TypeORM query:

async exportUsers(stateId: string, zipcodes: string) 
{
  //zipcodes = '60563', '54656', '94087';//
  const query = await this.userRepository
  .createQueryBuilder('user')
  .select('user.email', 'email')
  .where('left(user.Zip,5) in :zip', { zip: zipcodes }); 
}

How to pass string containing 'array of strings' to TypeORM query using IN.

2 Answers 2

5

This worked:

zipcodes = '60563', '54656', '94087';
const ziplist: string[] = zipcodes.replace("'", "").split(",");

Changed query to:

.where('left(s.ShipToZip,5) in (:...zip)', { zip: ziplist }); 
Sign up to request clarification or add additional context in comments.

Comments

0

Replace your where clause with this code:

.where("left(user.Zip,5) IN (:zip )", { zip : zipcodes })

Note: your zipcode variable should be in array format; in means:

zipcodes = ['94085','54656','94087']

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.