Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
IF statement
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Divers
Thread ID:
00962743
Message ID:
00963125
Vues:
12
>Thanks
>Sergey,
>That explains why even after trimming my variable it didn't work.
>It's always nice to return from lunch to a solved problem!
>
>
>
>>Because default lenght for char type in this case is one caracter, IOW it's the same as
declare @sOsmOsc char(1)
I recomend that you always specify size.
declare @sOsmOsc char(3)
>>-- Or
>>declare @sOsmOsc varchar(32)
>>
>>>I thought this was as simple as it gets but:
>>>Can someone tell me why the following IF statement fails?
>>>I would have expected this to match but my SET command only executes if I set the condition to !=.
>>
>>>Declare @oscString character
>>>declare @sOsmOsc character
>>>set @sOsmOsc = 'OSC'
>>>
>>>IF @sOsmOsc = 'OSC'
>>>       SET @oscString = 'T'
>>
Chris,

In addition to what Sergey told you, when you define a variable as char or character, in effect, you've created a variable that has the maximum length of one character.

This can be particularly disturbing if you're trying to concatenate strings. In this case, in T-SQL, use varchar, indicating the maximum string length,
George

Ubi caritas et amor, deus ibi est
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform