Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
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: Tuesday, August 12, 2014 6:57 AM
Points: 8, Visits: 44
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 @ 1:36 AM
Points: 12,910, Visits: 32,029
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

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #733747
Posted Friday, June 12, 2009 10:25 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 12:36 AM
Points: 36,995, Visits: 31,524
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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

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

Add to briefcase

Permissions Expand / Collapse