please advice how to correct this query
$no_of_hours = DB::Table('shifts')
->where('time_sheet_id','=', $timesheet_id->id)
->selectRaw("SELECT time(sum(TIMEDIFF( 'shift_end_time', 'shift_start_time' )))")
->get();
return $no_of_hours;
im getting following error
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT time(sum(TIMEDIFF( 'shift_end_time', 'shift_start_time' ))) from `shifts`' at line 1 (SQL: select SELECT time(sum(TIMEDIFF( 'shift_end_time', 'shift_start_time' ))) from `shifts` where `time_sheet_id` = 35)
You have a sintax error probably because you don't have to write the SELECT keyword in the selectRaw function ( the keyword is added implicity by the query builder in this case ):
->selectRaw("time(sum(TIMEDIFF( 'shift_end_time', 'shift_start_time' )))")
Related
I'm trying to convert a MS Access application to SQL Server. I'm getting an error
incorrect syntax near 'as'
when trying to convert this:
RegSales:
Sum(LOTOSMIS_ACC_TYPE.sing_ind*LOTOSMIS_RET_DAILY.grs_amn*IIf(gm_cd In (1105,2123,2124,2150,2152,2191,2192,5143,5145,5146,5245,5253),Switch(LOTOSMIS_RET_DAILY.gm_var=1,0,True,1),0))
To this
(SELECT CASE WHEN P.GM_VAR = 1 THEN 0 END)) AS RegSales,
I am getting error RegSales:
Sum(LOTOSMIS_ACC_TYPE.sing_ind*LOTOSMIS_RET_DAILY.grs_amn*IIf(gm_cd In (1105,2123,2124,2150,2152,2191,2192,5143,5145,5146,5245,5253),Switch(LOTOSMIS_RET_DAILY.gm_var=1,0,True,1),0))
Getting syntax errors
Incorrect syntax near the word 'as'
or
Incorrect syntax near ')'
What am I doing wrong?
If I follow correctly, the logic is:
sum(case when gm_cd not in (1105, 2123, 2124, 2150, 2152, 2191, 2192, 5143, 5145, 5146, 5245, 5253)
then LOTOSMIS_ACC_TYPE.sing_ind * LOTOSMIS_RET_DAILY.grs_amn
else 0
end)
I have a SQL question. The following piece of SQL code gives a "SQL Error [156] [S0001]: Incorrect syntax near the keyword 'WHERE'." Why does this error occure?
INSERT INTO [Layer](ComponentNumber)
OUTPUT inserted.ComponentNumber
VALUES (:component_number)
WHERE LayerID = :layer_id
I appreciate your answer!
Presumably, you want an update:
UPDATE [Layer]
SET ComponentNumber = :component_number
OUTPUT inserted.ComponentNumber
WHERE LayerID = :layer_id;
It is unclear why you would use an OUTPUT clause for this. You are passing in the value for ComponentNumber.
I am making a UNION between these two queries:
$first =
DB::table('pedido')
->select(DB::raw('date(fecha_pago) as fecha'),DB::raw('sum(subtotal) as ingreso'),DB::raw('0 as egreso'))
->where('idestado','=','2')
->groupBy(DB::raw('date(fecha_pago)'));
$second =
DB::table('egreso')
->select(DB::raw('date(fecha) as fecha'),DB::raw('0 as ingreso'),DB::raw('sum(monto) as egreso'))
->groupBy(DB::raw('date(fecha)'));
$final_query=
DB::select(DB::raw('date(fecha),sum(ingreso) as ingreso,sum(egreso) as egreso'))
->union($first)->union($second)
->groupBy(DB::raw('date(fecha)'))
->get();
I get the error:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'date(fecha),sum(ingreso) as ingreso,sum(egreso) as egreso' at line 1 (SQL: date(fecha),sum(ingreso) as ingreso,sum(egreso) as egreso)
DB::select() executes a raw query, unlike DB::table()->select() which is used to define fields for the query builder to select.
You're missing the DB::table() in your final query, without it, you won't be using the query builder and you'll actually be running a query of just date(fecha),sum(ingreso) as ingreso,sum(egreso) as egreso.
https://laravel.com/docs/5.6/queries#selects
I have the following SQL query in impala
SELECT currentdate,close
FROM ( SELECT * FROM spyprice)
Where currentdate between '2015-01-16' and '2016-06-17';
And it is giving me the error:
Starting Impala Shell without Kerberos authentication
ERROR: AnalysisException: Syntax error in line 15:
WHERE currentdate BETWEEN '2015-01-16' and '2016-06-17'
^
Encountered: WHERE
Expected: AS, DEFAULT, IDENTIFIER
CAUSED BY: Exception: Syntax error
Anyone knows what's going on?
Thanks in advance!
#James Xiang The right syntax of the query statement is :
SELECT a.currentdate, a.close FROM
(
SELECT * FROM spyprice
) a
Where a.currentdate between '2015-01-16' and '2016-06-17';
I have an error with this sentence:
...
WHERE title LIKE '%$title%' OR text LIKE '%$title%'
AND (price BETWEEN $minprice AND $maxprice)
AND catid = $catid ORDER BY id DESC
Error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND ) AND cat' at line 34
I did something wrong?
Evaluating "$maxprice" gives an empty string, probably because the variable $maxprice it is not defined. It could be a typo, or that you forgot to set a value for this variable.
Check your $maxprice Variable - it seems to be empty.