# Check given number

• anandhakrishnabca-1021414

SSC Veteran

Points: 222

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....

• Lowell

SSC Guru

Points: 323442

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!

• Jeff Moden

SSC Guru

Points: 995144

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.
"If you think its expensive to hire a professional to do the job, wait until you hire an amateur."--Red Adair
"Change is inevitable... change for the better is not."
When you put the right degree of spin on it, the number 3|8 is also a glyph that describes the nature of a DBAs job. 😉

How to post code problems
Create a Tally Function (fnTally)

• John Hanrahan

Hall of Fame

Points: 3825

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

• Jeff Moden

SSC Guru

Points: 995144

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.
"If you think its expensive to hire a professional to do the job, wait until you hire an amateur."--Red Adair
"Change is inevitable... change for the better is not."
When you put the right degree of spin on it, the number 3|8 is also a glyph that describes the nature of a DBAs job. 😉

How to post code problems
Create a Tally Function (fnTally)

• John Hanrahan

Hall of Fame

Points: 3825

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.

• Jeff Moden

SSC Guru

Points: 995144

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.
"If you think its expensive to hire a professional to do the job, wait until you hire an amateur."--Red Adair
"Change is inevitable... change for the better is not."
When you put the right degree of spin on it, the number 3|8 is also a glyph that describes the nature of a DBAs job. 😉