Icon View Thread

The following is the text of the current message along with any replies.
Messages 11 to 14 of 14 total
Thread Using TDataSet to find a record based on date
Tue, Jul 25 2017 9:58 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Richard,

<< The dataset, is SQL as follows: >>

That's not correct.  You can't use quotes around parameter names (they also shouldn't contain spaces):

SELECT * FROM PWReadings
WHERE CAST("_created" AS DATE)=DATE {SearchDate}

(Notice the space after the DATE keyword)

<< and I pass in a parameter, within EWB such as: >>

That's also wrong.  DateToStr is going to, by default, give you a date that is formatted for EWB client applications in the form of 'M/d/yyyy'.  That is no good for a date literal for EDB, which expects an ANSI date format of 'yyyy-M-d'.

Tim Young
Elevate Software
www.elevatesoft.com
Wed, Jul 26 2017 10:04 AMPermanent Link

Richard Mace

Tim Young [Elevate Software] wrote:

<< and I pass in a parameter, within EWB such as: >>

<< That's also wrong.  DateToStr is going to, by default, give you a date that is formatted for EWB client applications in the form of 'M/d/yyyy'.  That is no good for a date literal for EDB, which expects an ANSI date format of 'yyyy-M-d'.>>

OK, I've now got the following error:
"Expected Date Constant but instead found 2017" after adjusting the EWB code to:

iYear  := YearOf(SearchDate,True);
iMonth := MonthOf(SearchDate,True);
iDay   := DayOf(SearchDate,True);

sSearchDate := IntToStr(iYear) + '-' + IntToStr(iMonth) + '-' + IntToStr(iDay);

DS.Params.Add('SearchDate=' + sSearchDate);

Any further pointers?

Thanks

Richard
Wed, Jul 26 2017 12:05 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Richard,

<< OK, I've now got the following error:
"Expected Date Constant but instead found 2017" after adjusting the EWB code to: >>

Date constants in SQL need to be surrounded with single quotes:

DS.Params.Add('SearchDate=' + QuotedStr(sSearchDate));

Tim Young
Elevate Software
www.elevatesoft.com
Thu, Jul 27 2017 7:19 AMPermanent Link

Richard Mace

Tim Young [Elevate Software] wrote:

<< Date constants in SQL need to be surrounded with single quotes:

DS.Params.Add('SearchDate=' + QuotedStr(sSearchDate)); >>

Thanks Tim. That's sorted it Smile

Richard
Previous PagePage 2 of 2
Jump to Page:  1 2
Image