jeudi 24 janvier 2019

Format decimal value in database in where clause

I want to get data from database but the format of values that are compared do not tally.

The numbers in database are saved in weird format - sometimes are rounded and some of those are decimals (10, 14, 15, 12.44, 16.10, etc.)

In array I have values rounded on 2 decimals though.

I want to get data from database like so:

$foundPayments = $this>paymentsRepo>newQuery()>whereRaw("CONVERT(DECIMAL(10,2),payments.amount) = :payments", ['payments' => $payments]);

Althought, I end up with an error like this: Syntax error: 7 ERROR: syntax error at or near ","

I am not sure if the code works in laravel 5.1 with sending params like I do but thats not really what I do care for in that - the same error apperars even when I do not use variable.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire