Incorrect syntax near ')' in SQL Server - sql

I am getting an error:
Incorrect syntax near ')'
while trying to run the SQL query shown below on SAP Business Objects Information design tool. The query executes just fine from SQL Server, but from SAP Information design tool, I get this incorrect syntax error while trying to see the table values.
SQL Error:
Valid SQL
;WITH XMLNAMESPACES('Callaway.CRM.DAL.Objects.VisitActivityDetail' as ns)
SELECT
r.value('(ns:*)[3]','nvarchar(1000)') AS VisitType
FROM
Activity
OUTER APPLY
XML.nodes('/ns:VisitActivityDetail/ns:VisitType') AS x(r)
WHERE
ActivityTypeID = 2
Can you please help me understand what is wrong here?

Related

Incorrect syntax while accessing SQL table using Python

I'm trying to access a SQL Express database using Python, but I keep getting an incorrect syntax error. I've tried a few variations based of other examples I've seen, but nothing's working.
import pyodbc
conn = pyodbc.connect(Trusted_connection='yes',
driver='{SQL Server}',
server='VACE1\RCARCHIVE',
database='TestDB')
cursor = conn.cursor()
cursor.execute("select * from 100000MTL1")
for row in cursor:
print(row)
The error is
pyodbc.ProgrammingError: ('42000', "[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near '100000'. (102) (SQLExecDirectW)")
I've tried changing the database and the name of the database, but I'm not sure if that is where the error is exactly, so I'm totally stuck now.
Escape your table name like this
select * from [100000MTL1]
since table names usually don't start with numbers.

Can't use CONCAT in Teradata from SQLWorkbenchJ

I have a script that used to run just fine from Teradata SQL Assistant. I am unable to get the exact same script to run from SQL Workbench/J. I have isolated the problem to one specific line. Here's the query:
SELECT
variable1 as name1,
variable2 as name2,
CONCAT(TRIM(variable3), ':', trim(variable4)) as name3
variable4 as name4,
FROM
table1
WHERE
variable4 between '2017-01-01' AND '2017-01-31';
The problem is the CONCAT line. If I comment that line out, code runs fine. If I leave that line in, I get the unhelpful message:
[Teradata Database] [TeraJDBC 16.10.00.07] [Error 3706] [SQLState 42000]
Syntax error: expected something between '(' and the 'TRIM' keyword. [SQL State=42000,
DB Errorcode=3706]
1 statement failed.
I say unhelpful, because that makes it sound like a syntax error, but this isn't a syntax error as far as Teradata is concerned. The exact same code ran fine on Windows Teradata SQL Assistant. But since OSX Teradata SQL Assistant is a dumpster fire, I have to try and run the script in SQL Workbench J.
Help, please?
There's no concat function in Teradata SQL, it's an ODBC function (sometimes) automatically translated by the ODBC driver to valid syntax. But SQL Workbench uses JDBC, which doesn't support this function.
Simply switch to Standard SQL ||:
TRIM(variable3) || ':' || trim(variable4)

OPENQUERY syntax issue SQL Server 2012

I have a function that returns a table that will need to be called remotely. Since this functionality is not supported by SQL at the moment, I will need to utilize OPENQUERY to do the following
OPENQUERY([Linked_Server],'Query')
However, I keep getting a syntax error when I put in the ip address for the linked server. Linked server is setup properly from the looks of it. I am getting the following error:
Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'OPENQUERY'.
The script is:
OPENQUERY('NN.NNN.N.NN','SELECT * FROM dbo.DBarBillers')
(where N's are the digits of the defined linked server's IP address).
Intellisense is putting the red line under OPENQUERY and the linked server argument
I have tried unquoting the ip address, and bracing it instead of quoting and all are yielding errors. Thoughts?
You need to select from the openquery so the syntax is
SELECT * FROM OPENQUERY([Linked_Server],'SELECT * FROM dbo.DBarBillers')

SQL Query "Syntax error near field"

I am using a middleware system to connect to a Database system. We are using a lookup functionality which in turn creates an SQL Query based on the conditions we have provided in it.
SQL QUERY CREATED:
SELECT "FunctionCode", "AUM", "Numerator", "Denominator", "EANUPC", "Length", "Width", "Height", "CategoryofEAN" FROM "tblIdocAlternateUOMs" WHERE MaterialNumber='09792021'
Error:
'Error processing request in sax parser: Error when executing statement for table/stored proc. 'table' (structure 'statement'): com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near 'FunctionCode'.'.
I have executed the above query in database system and it is working fine without the errors but I am seeing the error in my system when I am trying to retrieve the data from DB.
DB System : Microsoft SQL SERVER
Could you please let me know why are these kind of errors usually appear?
SELECT
FunctionCode,
AUM,
Numerator,
Denominator,
EANUPC,
Length,
Width,
Height,
CategoryofEAN
FROM
tblIdocAlternateUOMs
WHERE
MaterialNumber='09792021'
one thing keep in mind that only value needs quotation mark and that is single quotes... nor field name...
Remove that quotation mark from coding side query.... Just because of this its hapening

SQL statement "WITH" doesn't work on Visual basic 6

I've just created a query which involves a selection on a table created by the WITH statement; I'd like to run in on a Visual Basic 6 application (connected to the database by an ADODB object) but I got an error message "incorrect syntax near the keyword "WITH", when I use the open method of a ADODB.recordset Object; it's like Visual Basic 6 doesn't understand this statement. How could I fix this? Is there an alternative way to perform the sql's WITH statement on Visual Basic 6?
A pound for a penny (in the absence of any more information and most likely incompleete error message) that the WITH does not have a preceeding ; because of a SET statement or DECLARE or some such.
Incorrect syntax near the keyword 'with'...previous statement must be terminated with a semicolon
Or OP is using SQL Server 2000 still...