Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFP DATE() vs. SQL GETDATE()
Message
From
25/04/2006 10:10:20
 
 
To
25/04/2006 09:59:04
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows NT
Database:
MS SQL Server
Miscellaneous
Thread ID:
01115333
Message ID:
01116359
Views:
16
>Hi Tore,
>
>>Pardon me for jumping in. You wrote "so I had tried: WHERE DATE()-31". This >is a terrible solution, even if it would have worked, because VFP, or MS->SQL, would have to evaluate DATE()-31 for every record! Always use >variables in where clauses, whenever possible. Use ldDate=date()-31 >followed by .. where datefield=ldDate.
>
>Glad you jumped in ... I'm completely 'self-taught' and always welcome a correction to my education.
>
>Let me make sure I understand ...
>
>If I had used "WHERE DATE()-31" in the SQL statment ... the DB server would have to make that comparison for each record in the DB. But, if I store DATE()-31 into a variable, then SQL can skip the 'every record check' and immediately pull the records that contain the date stored in the variable (or, are within a date range provided by a couple of variables), correct?

Right! I have very limited experience with MS-SQL, but I see no reason why it should not behave the same way. Whenever you select ....where yourfield=yourvalue, yourvalue should always be a value or a memory variable, not a function.

>I have known for a very long time that you can't (shouldn't) create a view on a large SQL table without parameters, as every record will come accross the LAN to the workstation. Therefore, I've always use variables, rather than selecting the whole table. However, I didn't realize that there was such a huge difference in putting a conditon in a WHERE clause or storing the results of the condition in a variable and then using the variable in the WHERE clause. When I think about it, this makes alot of sense but I had just missed this piece of knowledge.
>
>Thanks,
>Robert

I have very limited experience with MS-SQL, but I see no reason why it should not behave the same way. Whenever you select ....where yourfield=yourvalue, yourvalue should always be a value or a memory variable, not a function.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform