Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to do var substitution?
Message
De
31/01/2001 09:42:29
Evans Carl
System Answers Consulting, Inc
Big Lake, Minnesota, États-Unis
 
 
À
31/01/2001 08:27:51
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00470308
Message ID:
00470596
Vues:
42
>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


Thanks Mike, for you respond. I was hoping there was a way to turn off the time portion. I have been changing about 40 store procedures because of this problem and I have about 100 more to go... The solution I am using is

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 @time1 < dateadd(day,1,@time2)

This is one only way I have been about to get transactions that occur during the business day of the getdate(). Since time2 activeX control in my VB application I have no way to put a time stamp on the date. Thanks again for your input.
¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø¤º°¤º°`°º¤ø¤º°¤º°
Carl Evans
CEO & President
System Answers Consulting, Inc.
MCSD .NET, ASP.NET, C#.NET, VB.NET,
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform