This question already has answers here:
MS SQL Exception: Incorrect syntax near '#P0'
(7 answers)
Closed 8 years ago.
I am updating queries to use the cfqueryparam after I was shown all the advantages to using cfqueryparam's. However I have now run into an error that I have not crossed before and not sure how to troubleshoot or where to look for the issue. I am guessing that it is a syntax issue.
Here is the error-
Error Executing Database Query.[Macromedia][SQLServer JDBC Driver][SQLServer]Incorrect syntax near '#P1'. The specific sequence of files included or processed is: C:\inetpub\wwwroot\cfleadsource\admin\MultipleAccountReassign_new.cfm, line: 170
Here is my query. As you can see the old query is commented out and has been replaced with the new query. It should be noted that the old query worked without issues and this is the first query on the page that has been altered. For the life of me I can not determine what is incorrect. Thanks for the help.
<cfquery name="GetAccounts" datasource="#dbConn#">
<!--- select top #callNum# * from contact where mar in (select mar from marselect where userid = #oUID# and mar not like '%branch%') order by newid() --->
select top <cfqueryparam value= "#callNum#" CFSQLType="CF_SQL_INTEGER"> * from contact where
mar in (select mar from marselect where userid = <cfqueryparam value= "#oUID#" CFSQLType="CF_SQL_INTEGER"> and mar not like '%branch%') order by newid()
</cfquery>
select top cannot use <cfqueryparam> for top rows without brackets.
You may try adding a bracket and see if it works: MS SQL Exception: Incorrect syntax near '#P0'
Related
This question already has an answer here:
Replacement for Left command in SQLite SQL
(1 answer)
Closed 7 months ago.
How to remove all characters from / to &.
UPDATE bal SET Perevod=substr(Perevod, INSTR(Perevod, '/.+&')-1)
WHERE INSTR(Perevod, '/.+&')>0;
You can use this because I believe there is no LEFT function in SQLite:
UPDATE bal
SET Perevod = substr(Perevod, 1, INSTR(Perevod, '/')-1)
WHERE INSTR(Perevod, '/')>0;
DEMO
I have been using the query below and it was working fine but now it's giving a SQL error.
There were no changes made that could cause this to stop working.
There is no Field 'APPLICATIONID' in the table.
QueueSQL=select distinct (convert(char(5),SkillsetID)+'='+Skillset) from iagentbySkillsetStat where ApplicationID > 10000
QueueMappingSQL=SELECT DISTINCT (convert(char(5),SkillsetID)+'='+Skillset), SkillsetID FROM iagentbySkillsetStat iagentbySkillsetStat WHERE (iagentbySkillsetStat.ApplicationID>10000)
DB- Intersystems Cache
Error details for the log files are below.
14/09/2016 11:20:05 a.m. > ERROR - SQL Error '[Cache ODBC][State : S1000][Native Code 29]
[C:\xlink\xlink Compiled Package\Xlink Application\Isps_Ul.exe]
[SQLCODE: <-29>:<Field not found in the applicable tables>]
[Cache Error: <<SYNTAX>errdone+2^%qaqqt>]
[Details: <Prepare>]
[%msg: < SQL ERROR #29: Field 'APPLICATIONID' not found in the applicable tables^select distinct ( convert ( char ( 5 ) , SkillsetID ) + :%qpar(1) + Skillset ) from iagentbySkillsetStat where ApplicationID >>]'
Question was also asked at InterSystems Developer Community, where I noticed that table names are different. So, the answer is, that table name is suddenly changed somehow.
This question already has answers here:
SQL Oracle LEFT JOIN and SUBQUERY error: ORA-00905: missing keyword
(2 answers)
Closed 9 months ago.
I have the following query:
SELECT *
FROM DELUSR.AGREEMENT AS agreement
WHERE agreement.MASTER_AGGREMENT_ID = 4;
After trying to run it, I get this error:
Error code 933, SQL state 42000:
ORA-00933: SQL command not properly ended
Line 1, column 1
Execution finished after 0 s, 1 error(s) occurred.
I am not sure how to decode this error message. The statement looks fine to me. Any insights into whats wrong with it?
Oracle accepts no AS for table aliases:
SELECT * FROM DELUSR.AGREEMENT agreement WHERE agreement.MASTER_AGGREMENT_ID = 4;
Using Advantage Database Server 8.1 I am having trouble executing a successful query. I am trying to do the following
SELECT * FROM Persons
WHERE LastName IN ('Hansen','Pettersen')
To check for multiple values in a column. But I get an error when I try to execute this query in Advantage.
Edit - Error
poQuery: Error 7200: AQE Error: State = 42000; NativeError = 2115; [iAnywhere Solutions][Advantage SQL Engine]Expected lexical element not found: ( There was a problem parsing the
WHERE clause in your SELECT statement. -- Location of error in the SQL statement is: 46
And here is the SQL i'm executing
select * from "Pat Visit" where
DIAG1 IN = ('43644', '43645', '43770', '43771', '43772', '43773', '43774',
'43842', '43843', '43845', '43846', '43847', '43848', '97804', '98961',
'98962', '99078')
Done
Does anyone have any Idea how I could do something similar in advantage that would be efficient as well?
Thanks
You have an extraneous = in the statement after the IN. It should be:
select * from "Pat Visit" where
DIAG1 IN ('43644', '43645', <snip> )
I have the following query that's returning the error: "Incorrect syntax near the keyword 'VIEW'." I've tried to find any reference of this instance online and in SO. If I overlooked a solution or if anyone has any suggestions I'd greatly appreciate it.
Query:
<cfquery datasource="#mydatasource#">
CREATE VIEW #arguments.bulkRow.request_by#_uploader_features_view
(
feature_products_id
, feature_text
, feature_priority
)
AS
SELECT
a1.tbl_products__products_id AS feature_products_id,
a1.tbl_productfeature__feature_text__1 AS feature_text,
1 AS feature_priority
FROM bulk_product_upload a1
WHERE processed = 0
AND request_by = <cfqueryparam value="#arguments.bulkRow.request_by#" cfsqltype="cf_sql_varchar">
AND LEN( a1.tbl_productfeature__feature_text__1 ) > 1
UNION
SELECT
a1.tbl_products__products_id AS feature_products_id,
a1.tbl_productfeature__feature_text__2 AS feature_text,
2 AS feature_priority
FROM bulk_product_upload a1
WHERE processed = 0
AND request_by = <cfqueryparam value="#arguments.bulkRow.request_by#" cfsqltype="cf_sql_varchar">
AND LEN(a1.tbl_productfeature__feature_text__2) > 1
...
UNION
SELECT
a1.tbl_products__products_id AS feature_products_id,
a1.tbl_productfeature__feature_text__20 AS feature_text,
2 AS feature_priority
FROM bulk_product_upload a1
WHERE processed = 0
AND request_by = <cfqueryparam value="#arguments.bulkRow.request_by#" cfsqltype="cf_sql_varchar">
AND LEN(a1.tbl_productfeature__feature_text__20) > 1
</cfquery>
This is an abbreviated form of the query but it should get you started and show the basic layout.
Thanks in advance,
JP
I ran some testing against my own SQL Server and it appears that parameterized queries cause problems when creating views. Removing the CFQUERYPARAM tags should correct the issue. Using CFQUERYPARAM with a standard select statement is a best practice, but in this case you're passing in SQL that will be executed every time the view is accessed, so the parameterization isn't able to get passed through into the view.
Here are a couple of examples using the same concept, but tables from one of my own databases.
The following produces the Incorrect syntax near the keyword 'view' error:
<cfset id="x" />
<cfquery>
create view #id#_view as
select * from AdminUser
where admID = <cfqueryparam cfsqltype="cf_sql_varchar" value="#id#" />
</cfquery>
The following works fine:
<cfset id="y" />
<cfquery>
create view #id#_view as
select * from AdminUser
where admID = '#id#'
</cfquery>
If anyone is able to locate a SQL Server reference which explains this in detail, feel free to edit this answer with a link.
I would also note that depending on the value of the ID, you might consider wrapping the view name with brackets. If the ID begins with a number the statement will fail as-is, but putting that into a bracketed statement will cover those situations (just be sure to use the bracket notation when querying the view as well). Example: create view [#id#_view]