Empty String behaviour for number datatype (e.g Float, int etc)

  • In Sql Server for float datatype, Empty String('') is treated as 0 and vice-versa.

    Problem:

    When passed as '' to the parameter in the procedure, it takes the value as 0 and stores 0. This value is used to save in the table for a particular column.

    The value should be stored as '' and not 0, as 0 is treated differently by the application.

    How do we retain the ''(Empty string) value when passed in float data type?

  • You don't.  It's really as simple as that.  Think about what you're saying here.

    How do we retain the ''(Empty string) value when passed in float data type?

    string....float/float....string   They are completely different.  It wouldn't be a float datatype if it could hold a string, even an empty one.  You need to redesign your application and database so data is represented correctly.

    Derrick Leggett
    Mean Old DBA
    When life gives you a lemon, fire the DBA.

  • One point to make:

    Have You considered allowing NULL values in the column ?

    A NULL would be considered "Value Not Known".

    But first consider if You REALLY need to allow null in your column.

    Allowing NULL values is considered bad database design in som schools,

    and in many cases cause more problems than they solve.

    /rockmoose


    You must unlearn what You have learnt

  • Yea, I don't believe in that school. If you don't know what the data is then don't say you do. However I agree either use NULL or you will have to store as a char type but then you open yourself to bad data.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply