Error When Using REPLACE In SQL

Posted on 2008-06-23
Last Modified: 2013-12-13
Hello.  I am Connecting to an Access db via ODBC.  I am using PHP to display my results, but I can't get the SQL REPLACE function to work.  If I were using MySQL, I would put the following into my select statement:
  "  REPLACE(permits.Date,'00:00:00','') as 'Date'  "

When I try to put that into the sql that hits the access db, I get this error:
"The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect., SQL state 37000 in SQLExecDirect "

What am I doing wrong?  Thanks a lot.

*Side Question*
What type of SQL am I using when I'm connected to an Access db through ODBC?
Question by:thedeal56
  • 5
  • 3

Expert Comment

ID: 21850392
Can you supply the sql statement you are using? Have you tried to execute that same sql statement directly within ms access?

Author Comment

ID: 21850407
I have not tried to run it in access, I'll do that right now.  Here is my entire statement:
$sql="SELECT REPLACE(Date,'00:00:00','') as Date ,[Customer Name],[Customer Address],[Permit Number]  FROM Permits

Expert Comment

ID: 21850424
I don't know for sure about MS Access, but it's possible that "date" is a keyword - in which case, you may need to put brackets around it:

SELECT REPLACE([Date],'00:00:00','') as [Date] ,[Customer Name],[Customer Address],[Permit Number]  FROM Permits

Author Comment

ID: 21850499
I put the brackets in, and now I get this message:
Undefined function 'REPLACE' in expression., SQL state 37000 in SQLExecDirect
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.


Accepted Solution

Chumad earned 125 total points
ID: 21850533
It seems that REPLACE cannot be used through an ODBC connection (Jet SQL). See the first response to the question on this page:

Author Comment

ID: 21850571
Ah, I see.  In my case, I might be able to get around it by chopping off the last 8 characters in the date field.  Thanks!

Author Closing Comment

ID: 31469954

Author Comment

ID: 21850637
I just thought I would post the statement that worked for me:

$sql="SELECT LEFT([Date],10) as Date1 ,[Customer Name],[Customer Address],[Permit Number]  FROM Permits


Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now