1 (edited by joshuA 2021-10-09 01:43:12)

Topic: Help with SQLExecute conversions

Hello folks,
.
I felt like this is a silly elementary question, but I cannot figure out how to convert the types that a SQLExecute returns.  It obviously works as a string, but for anything else:

var dateHire : date;

dateHire := strToDate(SQLExecute('SELECT dateHire FROM employee where ID = ' + frmEmpRecord.tbEmpID.Text));

or

dateHire := strToDateTime(SQLExecute('SELECT dateHire FROM employee where ID = ' + frmEmpRecord.tbEmpID.Text));

.
I get "not a valid date and time"
.
and
.

dateHire := SQLExecute('SELECT dateHire FROM employee where ID = ' + frmEmpRecord.tbEmpID.Text);

.
I get "could not convert variant of type (UnicodeString) into type (Double)"
.
so then I try:
.

var dateHire : double;

dateHire := StrToFloat(SQLExecute('SELECT dateHire FROM employee where ID = ' + frmEmpRecord.tbEmpID.Text));

.
I get "not a valid floating point value"
.
so then I try removing the StrToFloat and get the (Unicode String) error again...
.
I sifted through several pages of forum posts for related examples.  I'm not sure what else to try.  Would someone be kind enough to help me out here?  I have had this issue in the past, but I usually found another way around it.  But I wanted to reach out and find the proper way of doing this for future use...

"Energy and persistence conquer all things."

Re: Help with SQLExecute conversions

Try using

var dateHire : TDateTime;
dateHire := SQLDateTimeToDateTime(
    SQLExecute('SELECT dateHire FROM employee where ID = ' + frmEmpRecord.tbEmpID.Text+' LIMIT 1')
);
Post's attachments

Attachment icon joshuA_Date.zip 547.35 kb, 296 downloads since 2021-10-09 

brian

Re: Help with SQLExecute conversions

I knew it was a simple answer.  I just couldn't find it (didn't know what to search for, or where to look).
.
Still learning the datatypes.  I stumbled across the SQLDateTimeToDateTime() today.  It may have also worked, but I haven't tested it.
.
I know about the f(x) reference in MVD.  When I choose the Types category, everything begins with T and I get overwhelmed there.  I guess I need to start referring to the delphi page now because I just noticed that type is listed there (more clearly for me).
.
Many thanks sir!

"Energy and persistence conquer all things."