Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
MySQL problem with parameters
Message
 
 
To
04/03/2010 19:43:13
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 8 SP1
Miscellaneous
Thread ID:
01452040
Message ID:
01452670
Views:
44
>>>I have a MySql table with a DateTime field. I want to get all the records for today.
>>>ldDate = DATE()
>>>=SQLEXEC(lnHandle,"SELECT * FROM myTable WHERE dtField = ?ldDate")
>>>This produces no records, which is expected since I'm not accounting for the time portion of the field. But when I tried
>>>=SQLEXEC(lnHandle,"SELECT * FROM myTable WHERE DATE(dtField) = ?ldDate")
>>>I also got no records back. When I tried
>>>ldDate = DATE()
>>>lcDate = TRANSFORM(DTOS(ldDate),"@R 9999-99-99")
>>>=SQLEXEC(lnHandle,"SELECT * FROM myTable WHERE DATE(dtField) = ?lcDate")
>>>I got the records I wanted.
>>>
>>>Could somebody tell me why passing a Date value doesn't work while passing a character representation of the date does work?
>>>
>>>Thanks............Rich
>>
>>Use lower range and upper range instead, e.g.
>>
>>ldStartDate = Date()
>>ldEndDate = date() + 1
>>
>>=SQLEXEC(lnHandle,"SELECT * FROM myTable WHERE dtField >= ?ldStartDate and dtField < ?ldEndDate")
>
>Thanks for responding. Sorry for delayed acknowledgement.
>
>It's possibly an instance of NIH syndrome ......... but I prefer my kludge (convert to a character representation of a date) to yours. I think it shows the desired result more clearly. I also discovered that
>ldDate = DATE()
>SQLEXEC(lnHandle,"SELECT * FROM myTable WHERE DATE(dtField) = CAST(?ldDate as date)")
>also works. I don't know which is the fastest expression (and don't think the difference would be at all significant) but I think this is the most clear, but that's a subjective opinion.

I know that in SQL Server the way I suggested is much better any other alternative. I expect it's better in MySQL too.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform