Home Forums SQL Server 2008 T-SQL (SS2K8) 0 is equal to zero length string. Can someone explain how this can be? RE: 0 is equal to zero length string. Can someone explain how this can be?

  • JasonRowland (8/4/2012)


    Ok, I think I understand why this is. There is an implicit conversion from varchar to int and you might think that when converting '' to int it would be null. But null isn't an int, it isn't anything. So, it converts it to 0. I would rather get a type conversion error though.

    In your sample as you stated it is a zero length string, and NOT null, if it were null your result would be:

    DECLARE @MyINT int = 0;

    declare @MyVarChar varchar(12) = NULL;

    IF @MyINT = @MyVarChar

    PRINT 'TRUE! 0 equals ''''';

    ELSE

    PRINT 'FALSE!';

    Result:

    FALSE

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]