SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Check given number


Check given number

Author
Message
anandhakrishnabca-1021414
anandhakrishnabca-1021414
Grasshopper
Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)

Group: General Forum Members
Points: 12 Visits: 49
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
Lowell
One Orange Chip
One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)

Group: General Forum Members
Points: 28111 Visits: 39939
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
Jeff Moden
SSC Guru
SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)

Group: General Forum Members
Points: 85747 Visits: 41091
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

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
John Hanrahan
John Hanrahan
SSC Eights!
SSC Eights! (803 reputation)SSC Eights! (803 reputation)SSC Eights! (803 reputation)SSC Eights! (803 reputation)SSC Eights! (803 reputation)SSC Eights! (803 reputation)SSC Eights! (803 reputation)SSC Eights! (803 reputation)

Group: General Forum Members
Points: 803 Visits: 1464
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
Jeff Moden
SSC Guru
SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)

Group: General Forum Members
Points: 85747 Visits: 41091
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

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
John Hanrahan
John Hanrahan
SSC Eights!
SSC Eights! (803 reputation)SSC Eights! (803 reputation)SSC Eights! (803 reputation)SSC Eights! (803 reputation)SSC Eights! (803 reputation)SSC Eights! (803 reputation)SSC Eights! (803 reputation)SSC Eights! (803 reputation)

Group: General Forum Members
Points: 803 Visits: 1464
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
Jeff Moden
SSC Guru
SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)

Group: General Forum Members
Points: 85747 Visits: 41091
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

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search