Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Using a calculated field
Message
 
 
À
19/10/2010 09:30:23
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Web
Divers
Thread ID:
01486104
Message ID:
01486109
Vues:
62
This message has been marked as the solution to the initial question of the thread.
>>You can have a computed field in your table (and add an index on this field).
>>
>>Field's definition will be
>>
>>dateadd(day, NumberOfDays, AddDate)
>>
>>Then, using this new field, you can write queries such as
>>
>>declare @Today date -- SQL Server 2008
>>
>>set @Today = cast(getdate() as date)
>>
>>select * from myTable where FutureDate < @Today
>
>Thanks, this is good. But, I need to avoid creating additional field or computed field in the table.

If so, you may try
select * from myTable where AddDate < dateadd(day,-1 * NumberOfDays, cast(getdate() as date)
-- assuming your AddDate field is indexed
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform