dhowells
2nd August 2011, 15:34
Hello.

I'm wondering what is the suggested solution when using date.num() in select statements. Is it better to have a variable or use the actual function. Both work fine, just curious if one is preferred over the other.

Thanks for any input,
Dan

Ex:
...
where tdpur045.date =:curr.date

vs.
...
where tdpur045.date = date.num()

zardoz
3rd August 2011, 19:51
IMHO, I think both have the same impact on performances...

in fact, in both the versions the database driver substitute the variable with a constant, because the : prefix indicates that is a external (to the query) variable.

...
where tdpur045.date = <value>
...

so, doesn't matter if the <value> is the result of date.num() function or a variable containing the same value. In the first case, I have to use a variable and assign to it date.num() before, so a performance reduction I could have in the first case, but so little that even the profiler cannot be aware.

Another way you can do this is thru forcing the binding of the variable:

where tdpur045.date = :1
....
wherebind(1, date.num())

I think all three version have the same impact on performances.