Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Check given number Expand / Collapse
Author
Message
Posted Friday, June 12, 2009 4:22 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, November 20, 2014 7:43 AM
Points: 8, 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....
Post #733661
Posted Friday, June 12, 2009 6:37 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 7:08 AM
Points: 14,557, Visits: 38,447
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!
Post #733747
Posted Friday, June 12, 2009 10:25 PM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 11:36 AM
Points: 42,081, Visits: 39,474
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."

Helpful Links:
How to post code problems
How to post performance problems
Post #734245
Posted Friday, December 18, 2015 2:07 PM
SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Yesterday @ 9:20 AM
Points: 660, Visits: 1,445
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
Post #1746355
Posted Friday, December 18, 2015 3:34 PM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 11:36 AM
Points: 42,081, Visits: 39,474
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."

Helpful Links:
How to post code problems
How to post performance problems
Post #1746365
Posted Monday, December 21, 2015 11:34 AM
SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Yesterday @ 9:20 AM
Points: 660, Visits: 1,445
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.
Post #1746840
Posted Monday, December 21, 2015 4:36 PM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 11:36 AM
Points: 42,081, Visits: 39,474
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."

Helpful Links:
How to post code problems
How to post performance problems
Post #1746939
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse