Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to do var substitution?
Message
De
31/01/2001 08:27:51
 
 
À
30/01/2001 16:34:14
Evans Carl
System Answers Consulting, Inc
Big Lake, Minnesota, États-Unis
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00470308
Message ID:
00470566
Vues:
34
You are correct that your datetime value does not have the time component and will not be equal to any other datetime value unless it too has its time component set to midnight.

The trick is to change the if to be a boundary check instead of direct equality:

>declare @time1 datetime
>declare @time2 datetime
>declare @string1 varchar(20)
>declare @string2 varchar(20)
>
>set @time1 = getdate()
>set @time2 = '01/30/00'
>
>
>select @time1
>select @time2
-- if @time2 >= @time1
if @time1 >= @time2 and @time1 < @time2+1
> begin
> set @string1 = "Your the Man"
> select @string1
> end
>else
> set @string2 = "Your the Woman"
> select @string2

This is really only reliable when the datetime does not have a time component.

-Mike
Michael Levy
MCSD, MCDBA
ma_levy@hotmail.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform