I'm trying to get a product by id between a specific date range but the problem I'm facing is:
- date is in string format
- for some weird reason dates are stored in the database with an incomplete timestamp (eg: '12-04-2020 12:21') which I'm trying to get rid of
Using Laravel's Eloquent below query works without the last line (AND...) which is my attempt to perform date conversion.
I may be able to solve this issue with MySQL but current task is to use SQL Server not really sure what went wrong here any help is much appreciable.
$id = 2;
$from = '01-03-2020';
$to = '01-05-2020';
$products = DB::select("SELECT DISTINCT
products.PRODUCT_ID,
products.PRODUCT_NAME,
TRANSACTIONS_DTL.PRODUCT_ID,
TRANSACTIONS_DTL.TRANS_ID,
TRANSACTIONS_DTL.PRODUCT_VALUE,
TRANSACTIONS_HD.TRANS_ID,
TRANSACTIONS_HD.TRANS_DATE
FROM
products
INNER JOIN TRANSACTIONS_DTL ON products.PRODUCT_ID = TRANSACTIONS_DTL.PRODUCT_ID
INNER JOIN TRANSACTIONS_HD ON TRANSACTIONS_DTL.TRANS_ID = TRANSACTIONS_HD.TRANS_ID
WHERE
products.PRODUCT_ID = $id
AND TRANSACTIONS_HD.TRANS_DATE > CONVERT(date,'$from') AND TRANSACTIONS_HD.TRANS_DATE < CONVERT(date,'$to')
");
TRANSACTIONS_HD.TRANS_DATEcolumn?