Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Error When Using REPLACE In SQL

Posted on 2008-06-23
8
Medium Priority
?
518 Views
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?
0
Comment
Question by:thedeal56
  • 5
  • 3
8 Comments
 
LVL 8

Expert Comment

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

Author Comment

by:thedeal56
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
0
 
LVL 8

Expert Comment

by:Chumad
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
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:thedeal56
ID: 21850499
I put the brackets in, and now I get this message:
Undefined function 'REPLACE' in expression., SQL state 37000 in SQLExecDirect
0
 
LVL 8

Accepted Solution

by:
Chumad earned 500 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: http://www.dbforums.com/archive/index.php/t-1059565.html
0
 

Author Comment

by:thedeal56
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!
0
 

Author Closing Comment

by:thedeal56
ID: 31469954
Thankyou
0
 

Author Comment

by:thedeal56
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

0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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.
Suggested Courses

927 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