[SOLVED]DATEPART fails- New to Lazarus lazarus / 16-Databases ---------------------------------------------------------------------- What I can do · 2024-09-01 17:33 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  SQLQuery1.Close; SQLQuery1.SQL.Text:='SELECT *, DATEPART('yyyy',ck_Date) as aYMDate From mytable'; SQLQuery1.ExecSQL; SQLQuery1.Open; ---------------------------------------------------------------------- tooldeveloper · 2024-09-02 02:33 Try the following instead: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i SQLQuery1.Close;  SQLQuery1.SQL.Text:='SELECT *, DATEPART(''yyyy'',ck_Date) as aYMDate From mytable';  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. ---------------------------------------------------------------------- What I can do · 2024-09-02 02:55 Thank you tooldeveloper but... Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  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 · 2024-09-02 05:30 In MS Access, use quotation marks instead of an apostrophe as a string delimiter Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i SQLQuery1.SQL.Text:='SELECT *, DATEPART("yyyy",ck_Date) as aYMDate From mytable';https://www.w3schools.com/Sql/func_msaccess_datepart.asp ---------------------------------------------------------------------- What I can do · 2024-09-02 05:34 Thank you, paweld My problem was bad data. I needed some working examples so I use ChatGPT to write some and it worked great.