Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL Select with DateTime and Int
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
01669054
Message ID:
01669055
Vues:
69
This message has been marked as the solution to the initial question of the thread.
>Hi,
>
>I wonder what I am doing wrong in this case. Here is the SQL Select (simplified):
>
>*-- The fields in SQL Server table:
>*-- PurchDate - Datetime
>*-- Years - Integer (from 1 to 100)
>dToday = date()
>cWhereExpr = "'" + DTOS( cToday ) "' >= (PurchDate + Years) "
>select * from MyTable where cWhereExpr
>
>
>Example: PurchDate is 2018-01-05 and Years is 10. But the record is included in the resulting query.
>Shouldn't the PurchDate + Years being much higher than the current date?
>
>UPDATE: I think my problem is that I have to convert Years into years since SQL Server sees it as Days. But how? Should I multiply the Years by 365? Or there is a better way to convert the int number into years?
dToday = date()
cWhereExpr = ['] + DTOS( cToday ) [' >=DATEADD(year, Years, PurchDate) ]
select * from MyTable where cWhereExpr
I'm confused. Your example is using pure VFP but you said you query SQL Server table?
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform