XQuery [nodes()]: Syntax error near '<eof>', expected a step expression - sql

Running the below SQL/XPath query returns the following error:
Query:
;WITH XMLNAMESPACES (
'http://schemas.microsoft.com/win/2004/08/events/event' as ns
, default 'http://schemas.microsoft.com/win/2004/08/events/event'
)
select [Events].[Event].value('(./System/TimeCreated/#SystemTime)[1]','nvarchar(100)') EventTime
from #xml.nodes('/*/Event/') [Events]([Event])
Error:
XQuery [nodes()]: Syntax error near '<eof>', expected a step expression.

From: http://www.experts-exchange.com/Database/MS-SQL-Server/Q_27789732.html
The issue was the / on the end of the xpath. i.e.
from #xml.nodes('/*/Event/') [Events]([Event])
Should have been:
from #xml.nodes('/*/Event') [Events]([Event])

Related

SQL Error [156] [S0001]: Incorrect syntax near the keyword 'WHERE'

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.

Nested select statements in impala sql

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';

Impala query: Exception: Syntax error caused by cast function

I have the following Impala query
select session_id, max(cast(milli_ts) as integer), min(cast(milli_ts) as integer)from my_table group by session_id
But got the following errors:
HiveServer2Error: AnalysisException: Syntax error in line 10:
...sion_id, max(cast(milli_ts) as integer), min(cast(mill...
^
Encountered: )
Expected: AND, AS, BETWEEN, DIV, ILIKE, IN, IREGEXP, IS, LIKE, NOT, OR, REGEXP, RLIKE
CAUSED BY: Exception: Syntax error
Any idea what I missed? Thanks!
The correct syntax for CAST is as following:
cast(milli_ts as integer)

hive date format error when used with the table

I have fields like date_column = 20140228 in the table 1. When I hard code the number like below it works, but when I specify the column name its failing. With error
H110 Unable to submit statement. Error while compiling statement: FAILED: ParseException line 2:1 cannot recognize input near 'select' 'date_format' '(' in select clause [ERROR_STATUS]
Working:
select date_format(from_unixtime(unix_timestamp(cast('2014022817' as string),'yyyyMMddHH')),'yyyy-MM-dd HH');
Failing:
select
select date_format(from_unixtime(unix_timestamp(cast(date_column as string),'yyyyMMddHH')),'yyyy-MM-dd HH')
from
table1
Why are you repeating the select? Try this:
select date_format(from_unixtime(unix_timestamp(cast(date_column as string
),'yyyyMMddHH'
)
),'yyyy-MM-dd HH'
)
from table1

Syntax Error In Query with selectRaw and time diff

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' )))")