Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SP parameter use = '' or NULL ?
Message
De
01/08/2005 03:49:22
 
 
À
29/07/2005 04:05:31
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Divers
Thread ID:
01036110
Message ID:
01037408
Vues:
30
Hi Steven,

Thank alot for your advise.

I am just wondering why when I pass '' inside my parameter of my SP,
the line "IF(LEN(@par1) > 0)" is true, The @par1 is length of 2
insteads of 0.

Do you know why ?
I am told use default of NULL insteads.


>Hi,
> I don't think "if(len(@para1) = 2) to check for empty parameter"
>is a good idea. Recommend "if(isnull(@para1,'') = ''" instead,
>then no matter which the @par1 is null or empty, it always returns correct value.Of course,you have to ensure any invisible characters,e.g.
>char(13)+char(10) are excluded from the parameter passed in,as Sergey mentioned.
> Reference to codes below:
>
>  declare @par1 varchar(100)
>select @par1=space(0)   -- +char(13)+char(10)
>select len(@par1), case when isnull(@par1,'')='' then 'True' else 'False'end
>select @par1=space(2)  -- +char(13)+char(10)
>select len(@par1), case when isnull(@par1,'')='' then 'True' else 'False'end
>
>
Best Regards
Virusim
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform