Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SP parameter use = '' or NULL ?
Message
From
01/08/2005 03:49:22
 
 
To
29/07/2005 04:05:31
General information
Forum:
Microsoft SQL Server
Category:
Other
Miscellaneous
Thread ID:
01036110
Message ID:
01037408
Views:
28
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform