Check given number

  • Hi,

    I want to validate the given number. how to check for the following requirements in sql server 2005

    1) how to check whether the given number is integer

    2) how to check whether the given number is decimal

    pls help me....

  • here's the first way i thought of: compare the value to the convert(,int) of itself.

    declare @number decimal(18,4)

    Set @number = 10.0

    --here's one way, compare the value to the integer conversion of itself.

    IF number = convert(int,@number)

    PRINT 'Can Be Integer'

    ELSE 'Must Remain Decimal

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • anandhakrishnabca (6/12/2009)


    Hi,

    I want to validate the given number. how to check for the following requirements in sql server 2005

    1) how to check whether the given number is integer

    2) how to check whether the given number is decimal

    pls help me....

    I'm curious... why do you need to do such a validation? What is the business rule behind it all?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Jeff,

    A business case for this might be inventory. In our case we had a clerk enter in an invalid unit of measure then she completed some transactions. This resulted in decimal places in our inventory when the items were 'whole'.

    Specifically in our case the item comes in a pack of 6. The master case should have had 10 packs of 6 in it. Instead she said it had .44 of a pack in it.

    John

  • John Hanrahan (12/18/2015)


    Jeff,

    A business case for this might be inventory. In our case we had a clerk enter in an invalid unit of measure then she completed some transactions. This resulted in decimal places in our inventory when the items were 'whole'.

    Specifically in our case the item comes in a pack of 6. The master case should have had 10 packs of 6 in it. Instead she said it had .44 of a pack in it.

    John

    What is the datatype of the "field" this entry was made to? I'm thinking that the front end would be the right place for this type of "business logic".

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • The front end can only do so much to stop bad user action. We have some items which allow decimal places and some that don't. Our system has a check for that but only if the person who sets it up does so 'correctly'. Alas it is not done correctly every time.

  • John Hanrahan (12/21/2015)


    The front end can only do so much to stop bad user action. We have some items which allow decimal places and some that don't. Our system has a check for that but only if the person who sets it up does so 'correctly'. Alas it is not done correctly every time.

    Agreed. With the idea of and simplicity of input data masking on the front end, I don't know why more people don't take advantage of such things for numeric and date/time "fields".

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 7 posts - 1 through 6 (of 6 total)

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