Forum > Databases
[SOLVED]DATEPART fails- New to Lazarus
(1/1)
What I can do:
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 [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- SQLQuery1.Close; SQLQuery1.SQL.Text:='SELECT *, DATEPART('yyyy',ck_Date) as aYMDate From mytable'; SQLQuery1.ExecSQL; SQLQuery1.Open;
tooldeveloper:
Try the following instead:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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:
Thank you tooldeveloper
but...
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- 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:
In MS Access, use quotation marks instead of an apostrophe as a string delimiter
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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:
Thank you, paweld
My problem was bad data.
I needed some working examples so I use ChatGPT to write some and it worked great.
Navigation
[0] Message Index