SQL Syntax Help - Incorrect syntax near '%'. 
Author Message
 SQL Syntax Help - Incorrect syntax near '%'.

Ok, using MS SQL Server 7.0, I am doing a simple query using JTurbo
jdbc driver.
I am accessing this through JBoss/Tomcat.

This is my sql:

select person.personid, person.lastname, i.storeid, i.id
from person
left outer join
  (select table2.personid,table2.eventdate,table3.*
  from table2
  join table3 on table2.id=table3.id ) i
on i.personid=person.personid
where (person.lastname like '%lastname%')
Order by lastname, person.personid desc

Whenever I run it, I get "Incorrect syntax near '%'."
However, if I copy/paste this to MS Query Analyzer, it works PERFECT.
I also have other queries which are similar, and they work fine.
Also, if I take the where( ... ) part out, it works fine (but I do not
get any where control, which is needed).

Any help would be appreciated.
Thanks,
  -- Chris



Tue, 29 Jun 2004 04:19:30 GMT
 SQL Syntax Help - Incorrect syntax near '%'.

I would guess that the query sent by the application is not as expected
since it works fine in QA.  You might try using SQL Profiler to view the
actual SQL received by SQL Server.

Hope this helps.

Dan Guzman
SQL Server MVP

-----------------------
SQL FAQ links (courtesy  Neil Pike):

http://www.ntfaq.com/Articles/Index.cfm?DepartmentID=800
http://www.sqlserverfaq.com
http://www.mssqlserver.com/faq
-----------------------


Quote:
> Ok, using MS SQL Server 7.0, I am doing a simple query using JTurbo
> jdbc driver.
> I am accessing this through JBoss/Tomcat.

> This is my sql:

> select person.personid, person.lastname, i.storeid, i.id
> from person
> left outer join
>   (select table2.personid,table2.eventdate,table3.*
>   from table2
>   join table3 on table2.id=table3.id ) i
> on i.personid=person.personid
> where (person.lastname like '%lastname%')
> Order by lastname, person.personid desc

> Whenever I run it, I get "Incorrect syntax near '%'."
> However, if I copy/paste this to MS Query Analyzer, it works PERFECT.
> I also have other queries which are similar, and they work fine.
> Also, if I take the where( ... ) part out, it works fine (but I do not
> get any where control, which is needed).

> Any help would be appreciated.
> Thanks,
>   -- Chris



Tue, 29 Jun 2004 22:15:01 GMT
 SQL Syntax Help - Incorrect syntax near '%'.
Could you put the java source in here?  I've experienced this kind of
situation before...sometimes, it comes down to how you send it, not
what you send.

JohnNarofsky

Quote:

> Ok, using MS SQL Server 7.0, I am doing a simple query using JTurbo
> jdbc driver.
> I am accessing this through JBoss/Tomcat.

> This is my sql:

> select person.personid, person.lastname, i.storeid, i.id
> from person
> left outer join
>   (select table2.personid,table2.eventdate,table3.*
>   from table2
>   join table3 on table2.id=table3.id ) i
> on i.personid=person.personid
> where (person.lastname like '%lastname%')
> Order by lastname, person.personid desc

> Whenever I run it, I get "Incorrect syntax near '%'."
> However, if I copy/paste this to MS Query Analyzer, it works PERFECT.
> I also have other queries which are similar, and they work fine.
> Also, if I take the where( ... ) part out, it works fine (but I do not
> get any where control, which is needed).

> Any help would be appreciated.
> Thanks,
>   -- Chris



Tue, 06 Jul 2004 21:35:34 GMT
 SQL Syntax Help - Incorrect syntax near '%'.
I figured out what the problem was.  It was how the ResultSet was
being created.  Using Query Analyzer, that one search was being done
with some weird goofy parameters and like 12 steps, while similar ones
were just straight 'select' statements, and took 3-4 steps.

I was creating a ResultSet that was not the default result set.  It
was one that was readonly, and scrollinsensitive.

Well, that apparently hosed the search, so I changed it to a default
resultset, and that works fine.

  -- pimpy

Quote:

> Could you put the java source in here?  I've experienced this kind of
> situation before...sometimes, it comes down to how you send it, not
> what you send.

> JohnNarofsky



Mon, 12 Jul 2004 01:47:44 GMT
 
 [ 4 post ] 

 Relevant Pages 

1. Help : Incorrect syntax near '@P1'

2. ODBC SQL Server Driver:Incorrect syntax near'.'.(#170)

3. 'Incorrect Syntax Near' message is worthless

4. Incorrect syntax near 'COLLATE'

5. Incorrect syntax near ',' using MSQuery

6. Incorrect syntax near '.'.(#170)

7. Incorrect syntax near 'Name'.

8. Incorrect syntax near 'GO'

9. UDF: Incorrect syntax near '.'

10. Incorrect syntax near 'COLLATE'

11. Incorrect syntax near the keyword 'convert'

12. Line 6: Incorrect syntax near '?'.


 
Powered by phpBB® Forum Software