I see the below error while connect and pull the records from the database through the Mule Database connector with an Oracle database. Can someone look at it and let me know what's wrong with this query.
Error:
"java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended\n"
type: DB:BAD_SQL_SYNTAX
Query:
SELECT A.sample_central_id,A.req_ndc_prod_id,B.lot_num,A.req_product_desc,A.req_hcp_fst_name,A.req_hcp_last_name,A.req_prof_desig,A.az_hcp_id,A.req_addr_line_1,A.req_addr_line_2,A.req_city,A.req_state_cd,A.req_zipcode,A.ffevnt_shipped_qty,A.ffevnt_ship_dt FROM scrf.ship_prod_hist_vw A,scrfval.ship_dtl B WHERE Trunc(A.req_sample_requested_dt)>= Trunc(SYSDATE - 30)AND Trunc(A.req_sample_requested_dt)<= Trunc(SYSDATE + 10)AND Trunc(A.ffevnt_ship_dt)>= Trunc(SYSDATE - 8)AND Trunc(A.ffevnt_ship_dt)<Trunc(SYSDATE - 1)AND Upper(A.lkp_brand_desc) LIKE '%LYNPARZA%' AND A.sample_central_id = B.sc_req_id AND A.ffevnt_ff_vendor_id = B.shipment_id AND A.req_ndc_prod_id = B.ndc_prod_id AND A.ffevnt_shipped_qty<>0 ORDER BY 1;
Try removing the semicolon (';') at the end.
Related
I am getting following error on insert statement for sqlite DB
could not prepare statement (1 near "undefined": syntax error)
I tried 2 variations of insert, for both error is same
var sql = "INSERT INTO Med(MedID) VALUES(?),";
sql += "['"+dataObj[i].MedID+"']";
var sql = "INSERT INTO Med(MedID) VALUES ('"+dataObj[i].MedID+"')";
tx.executeSql(sql);
The correct way to give parameters to an SQL statement is as follows:
var sql = "INSERT INTO Med(MedID) VALUES (?)";
tx.executeSql(sql, [dataObj[i].MedID]);
It looks like you are missing the space that is needed between the table name and the column names.
Try this:
var sql = "INSERT INTO Med (MedID) VALUES ('"+dataObj[i].MedID+"')";
tx.executeSql(sql);
Make sure your dataObj[i].MedID is also defined. Add a console.log(sql) before your executeSql statement to check the command before using it.
I am trying to execute a sql query that involves a LIKE operator with DBAL
Basically my query is the following:
public function getSubsiteByHostname($host){
$sql = "SELECT A.id, A.title, A.layout_id
FROM sites AS A
LEFT JOIN layouts B
ON A.layout_id = B.id
WHERE A.baseurl LIKE '%:host%'
";
$stmt = $this->db->prepare($sql);
$stmt->bindValue("host", $host);
$stmt->execute();
return $stmt->fetch();
}
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 '%'hostname.dev'%
Obiviously I'm doing something wrong with the bindValue
The answer is easier than I thought, like Adam suggested
$stmt->bindValue("host", '%'.$host.'%');
I set up a SQLite db with the same schema as my existing SQL server db and noted the following...
SQLite field names (and presumably everything else) are case sensitive.
MicroLite's SqlBuilder appears to insert the prefix 'dbo.' before the table name, which SQLite doesn't like...
This query works...
query = new SqlQuery("SELECT [ClubID], [Name] FROM [Clubs] WHERE [ClubID] = #p0", 3);
clubs = session.Fetch<MicroLiteClub>(query);
This one doesn't...
query = SqlBuilder.Select("*")
.From(typeof(MicroLiteClub))
.Where("ClubID = #p0", 3)
.OrWhere("ClubID = #p1", 22)
.OrderByDescending("Name")
.ToSqlQuery();
clubs = session.Fetch<MicroLiteClub>(query);
MicroLite logged: "no such table: dbo.Clubs"
This is happening because SQLite doesn't support table schemas like MS SQL Server does.
In the hand crafted query, you are not specifying a schame for the table FROM [Clubs] however in your mapping attribute you will have specified dbo as the schema like this:
[Table(schema: "dbo", name: "Clubs")]
The SqlBuilder doesn't know what SQL Dialect is in use so if a schame is present on the table mapping, it will be used. This means that it would generate FROM [dbo].[Clubs]. To rectify this, simply remove the schema value on the TableAttribute as is optional from MicroLite 2.1 onwards.
On a side note, MicroLite 2.1 introduced support for In in the SqlBuilder fluent API so you could change:
.Where("ClubID = #p0", 3)
.OrWhere("ClubID = #p1", 22)
to
.Where("ClubID").In(3, 22)
Using MS SQL 2000 it was possible to have a query such as:
SELECT (Code + ' = ' + EdiNumber + ',') AS MyResult FROM tblCountry
Which would give you a list of results like:
MyResult
========
ZW = 263,
ZA = 27,
...
However, in MS SQL 2008 that query returns:
-1 records affected
Does anyone know a) Why? and b) How to get the SQL 2000 result from SQL 2008?
UPDATE
Im just using a standard ASP.NET connection string to connect to the database using a console to post the query:
Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MyDB.mdf;Integrated Security=True;User Instance=True; Database=MyDB
PROBLEM SOLVED
-1 records affected was clearly the non-privileged result because all that was actually happening was an error in the query whilst trying to concatenate a string (Code) and an int (EdiNumber)
The correct query should have been:
SELECT (Code + ' = ' + CAST(EdiNumber AS VARCHAR) + ',') as MyResult FROM tblCountry
Once I got that correct, the query worked fine from the original console.
I started to use DataSet in my ASP.net web app like 6 months ago. It is a beautiful tool, allow me to rapidly develop MVC application without having to do all the dirty works in DB connection/queries.
But today I faced some weird problem. It started with this query:
select a.MR_PART_CODE as PART_CODE,
b.PART_DESC as PART_DESC,
b.PM_MAD_CAT_CODE as CATEGORY,
c.MPC_MIN_QTY as CAT_SS,
a.MR_MAX_LEAD_TIME as LEAD_TIME,
a.MR_MAD as MAD,
ROUND((a.MR_MAD * a.MR_MAX_LEAD_TIME)) as CAL_SS,
greatest(ROUND((a.MR_MAD * a.MR_MAX_LEAD_TIME)),c.MPC_MIN_QTY) as SS,
d.SOH as SOH,
d.SOO as SOO,
(select sum(back_order) from STK_REQUEST where part_code=b.part_code) as BO,
(d.SOH+a.MR_SOO) as AVAIL,
((d.SOH + a.MR_SOO)-greatest(ROUND((a.MR_MAD * a.MR_MAX_LEAD_TIME)),c.MPC_MIN_QTY)) as ROQ,
(d.SOH - greatest(ROUND((a.MR_MAD * a.MR_MAX_LEAD_TIME)),c.MPC_MIN_QTY) ) as VAR,
a.MR_REMARKS as REMARKS
from ROQ a, PART_MASTER b, MAD_PARTS_CATEGORY c, PART_STATS d
where a.MR_PART_CODE = b.PART_CODE
and d.PART_CODE = b.PART_CODE
and b.PM_MAD_CAT_CODE = c.MPC_CAT_CODE
and b.RETIRE_FLAG = 'N'
and a.mr_year = (select max(mr_year) from roq)
and a.mr_month = (select max(mr_month) from roq where mr_year= (select max(mr_year) from roq))
and a.mr_period = (select max(mr_period) from roq where mr_month=(select max(mr_month) from roq where mr_year= (select max(mr_year) from roq)) and mr_year= (select max(mr_year) from roq))
and greatest(ROUND((a.MR_MAD * a.MR_MAX_LEAD_TIME)),c.MPC_MIN_QTY) > d.SOH`
The query ran fine in Toad for Oracle, but apparently it fails when I tried to setup as a new query in DataAdapter object. It says something like "Error in list of function arguments: SELECT not recognized" to this line:
(select sum(back_order) from STK_REQUEST where part_code=b.part_code) as BO
What did I do wrong?
FYI, the database is Oracle.
It seems to be an exception from some ASP class trying to parse your SQL. There would be an ORA-xxxxx error number if the message came from Oracle.
You shouldn't put SQL like that in ASP. Create a view instead, perhaps it's ok then.