Recent

Author Topic: [SOLVED]DATEPART fails- New to Lazarus  (Read 685 times)

What I can do

  • Full Member
  • ***
  • Posts: 155
[SOLVED]DATEPART fails- New to Lazarus
« on: September 01, 2024, 07:33:50 pm »
OS:Windows 10@64
Lazarus:3.22
DB with *.mdb  Access@32 bit
Project: Make a new temp Field upon query call
"aYMDate"

but all attempts failed,
Code: Pascal  [Select][+][-]
  1.  SQLQuery1.Close;
  2.  SQLQuery1.SQL.Text:='SELECT *, DATEPART('yyyy',ck_Date) as aYMDate From mytable';
  3.  SQLQuery1.ExecSQL;
  4.  SQLQuery1.Open;
  5.  

« Last Edit: September 02, 2024, 07:29:36 am by What I can do »

tooldeveloper

  • Newbie
  • Posts: 5
Re: DATEPART fails- New to Lazarus
« Reply #1 on: September 02, 2024, 04:33:46 am »
Try the following instead:
Code: Pascal  [Select][+][-]
  1. SQLQuery1.Close;
  2.   SQLQuery1.SQL.Text:='SELECT *, DATEPART(''yyyy'',ck_Date) as aYMDate From mytable';
  3.   SQLQuery1.Open;

The 'yyyy' needs two single quotes at beginning and end. The ExecSQL method is only for executing a statement that doesn't return a result.
« Last Edit: September 02, 2024, 04:44:20 am by tooldeveloper »

What I can do

  • Full Member
  • ***
  • Posts: 155
Re: DATEPART fails- New to Lazarus
« Reply #2 on: September 02, 2024, 04:55:30 am »
Thank you tooldeveloper
but...
Code: Pascal  [Select][+][-]
  1.  SQLQuery1.SQL.Text:='SELECT *, DATEPART(''yyyy'',ck_Date) as aYMDate From mytable';

Tried two apostrophe and even tried quota but errored out both times

paweld

  • Hero Member
  • *****
  • Posts: 1361
Re: DATEPART fails- New to Lazarus
« Reply #3 on: September 02, 2024, 07:30:39 am »
In MS Access, use quotation marks instead of an apostrophe as a string delimiter
Code: Pascal  [Select][+][-]
  1. SQLQuery1.SQL.Text:='SELECT *, DATEPART("yyyy",ck_Date) as aYMDate From mytable';
https://www.w3schools.com/Sql/func_msaccess_datepart.asp
Best regards / Pozdrawiam
paweld

What I can do

  • Full Member
  • ***
  • Posts: 155
Re: [SOLVED]DATEPART fails- New to Lazarus
« Reply #4 on: September 02, 2024, 07:34:22 am »
Thank you, paweld
My problem was bad data.
I needed some working examples so I use ChatGPT to write some and it worked great.
« Last Edit: September 02, 2024, 07:42:35 am by What I can do »

 

TinyPortal © 2005-2018