Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 12-09-2017, 01:39 PM
kbboykin kbboykin is offline
Senior Member
 
Join Date: May 2005
Posts: 367
Default How to use this ADO SQL in Delphi 2010

Please help. I am trying to return the month integer as the month name in an app. This works in Access 2010, but fails in Delphi 2010:

SELECT MonthName(hmonth, 3) AS MName, *
FROM provhedis
ORDER BY hyear, hmonth, provlastname;

What am I doing wrong or missing? I want to display the mon as a name in the dbgrid instead of the number.
__________________
Using Delphi 2010 Professional as a Novice Programmer - self taught
Reply With Quote
  #2  
Old 12-11-2017, 01:52 AM
drama22 drama22 is offline
Senior Member
 
Join Date: Jul 2014
Posts: 201
Default

lets say that you grabbed the full date AsDateTime you can use

MonthOf(thedate); in DateUtils unit

if not you can use encodedate and return monthof after that
Reply With Quote
  #3  
Old 12-11-2017, 09:42 AM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,305
Default

And what is your connectionstring?
I guess this MonthName is prevented by your current driver specified there.

This provider should be able to call this MonthName
Provider=Microsoft.ACE.OLEDB.12.0

You could also try How to configure Jet 4.0 to prevent unsafe functions from running in Access

And if all else failes just translate it in your query manually, perhaps Switch works...
Reply With Quote
  #4  
Old 12-11-2017, 11:29 AM
kbboykin kbboykin is offline
Senior Member
 
Join Date: May 2005
Posts: 367
Default Solved

@Norrit. I am using the Jet 4.0 database. I have subsequently learned that it will not support MonthName function, only Ace engine will. Nonetheless, I have found the solution from Kobik at stackoverflow.com.

SELECT Format(hmonth * 30, 'MMM') AS MName, *
FROM provhedis
ORDER BY hyear, hmonth, provlastname;

This will give me the correct Month Name based on the month integer that is stored in my table, when I run the query against it.
__________________
Using Delphi 2010 Professional as a Novice Programmer - self taught
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 01:59 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2018, vBulletin Solutions, Inc.