Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SELECT-SQL, DATE() and DATETIME()
Message
From
31/05/2003 08:00:41
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
30/05/2003 13:29:35
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00794631
Message ID:
00794855
Views:
11
>Hi
>
>Reading the messages of the several forum on VFP, I have inasmuch as the totality of the Select-sql is written using DATE() and DATETIME() directly.
>
>But DATE() to DATETIME() are estimated only once, to the beginning of the query, or for every evaluation made in the query ?
>
>On MSQL, GETDATE() is evaluate only at begin, and is costant within the query.
>
>Example:
>
>SELECT ..GETDATE()... FROM ... GETDATE() ....
>
>is equal to
>
>DECLARE @now DATETIME
>SET @now = GETDATE()
>SELECT .. @now ... FROM ... @now ....
>
>
>
>On VFP, DATE() and DATETIME() is eval for every evaluation in the query.
>It slows down the query execution, but can build wrong result.
>
>Example:
>
>CREATE CURSOR pivot (id I AUTOINCR )
>FOR i=1 TO 1000000
> APPEND BLANK
>NEXT
>SELECT id,DATETIME() FROM pivot && WHERE (DATETIME()-DTOT(DATE()))%2=0
>
>is not equal to
>
>m.now = DATETIME()
>SELECT id,m.now FROM pivot && WHERE (m.now-DTOT(DATE()))%2=0
>
>
>
>I think:
>
>we are fortunate:
>
>- little customers work to midnight;
>- a lot often the query comes executed in little second ones.
>
>Comment.
>
>Fabio

So Fabio,
Is this good or bad ?
In VFP you still have a chance to fix it with by assigning to a variable first.
Yes we're fortunate, in SQL server not every function is evaluated once at top.
OTOH in SQL server isn't it cryptic while some 'that should be dynamic' behave as if they're static but not all ? In SQL server that leads me to test each function for dynamicity first. In VFP I know if a function would return different values on successive calls then it'd in SQL too. More consistent IMHO.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform