October 27, 2011 at 11:17 am
Is there anyway to findout if passed parameter is INTEGER or DECIMAL(NUMERIC)?
October 27, 2011 at 11:33 am
Walton (10/27/2011)
Is there anyway to findout if passed parameter is INTEGER or DECIMAL(NUMERIC)?
Passed from where to where? using what technology?
I'm sorry but as currently stated - there's no good way to answer.
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
October 27, 2011 at 11:44 am
I am talking about the store proc on SQL Server. Store proc is passing the numeric value always. But looking at the numeric if it is INT(meaning numeric value without decimal) I need to process that seperately and If it is decimal(meaning numerica value with decimal) kind I need to process it separately.
For eg:
IF(@para=int(123))
do this
If(@para=int(123.12)
do this
October 27, 2011 at 11:55 am
Huh?
What is the reason to have to do something if it is an integer, and something else if it is not an integer?
Is the data type of the parameter coming from two different places in the front end?
In this case, another parameter should be created to indicate what to do.
Or, are you having trouble doing the same math on integers and numerics?
What language is this syntax from?
IF(@para=int(123))
do this
If(@para=int(123.12)
do this
Michael L John
If you assassinate a DBA, would you pull a trigger?
To properly post on a forum:
http://www.sqlservercentral.com/articles/61537/
October 27, 2011 at 11:59 am
You could compare the passed value with the FLOOR() of the passed value and see if they are different. For example:
IF @Param1 = FLOOR(@Param1)
PRINT 'Whole number'
ELSE
PRINT 'Not a whole number'
October 27, 2011 at 12:24 pm
The Floor() comparison is what I'd do.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
October 27, 2011 at 12:35 pm
Thanks Jon Fox. It worked perfectly.
October 27, 2011 at 2:26 pm
Be careful with FLOOR for example:
DECLARE @Msg1 VARCHAR(20)
DECLARE @Type1 VARCHAR(10)
SET @Type1 = 'INT'
DECLARE @PARAM1 INT
SET @PARAM1 = 13
IF @Param1 = FLOOR(@Param1)
SET @Msg1 = 'Whole number'
ELSE
SET @Msg1 ='Not a whole number'
DECLARE @Msg2 VARCHAR(20)
DECLARE @Type2 VARCHAR(10)
SET @Type2 = 'Decimal'
DECLARE @PARAM2 DECIMAL(3,1)
--note decimal point but no fractional value
-- 13.0 also acts in this manner
SET @PARAM2 = 13. IF @Param2 = FLOOR(@Param2)
SET @Msg2 = 'Whole number'
ELSE
SET @Msg2 = 'Not a whole number'
SELECT FLOOR(@Param1) AS 'Floor1',@Param1 AS 'Input value1',@Msg1,FLOOR(@Param2) AS 'Floor2',@Param2 AS 'Input value2',@Msg2
Floor1Input value1(No column name)Floor2Input value2(No column name)
1313 Whole number 1313.0 Whole number
October 27, 2011 at 2:53 pm
@Bitbucket I guess it depends on what Walton is actually trying to do. I was assuming that for his purposes 13 and 13.0 were equivalent; that very well may have been a faulty assumption on my part though. You're absolutely correct that FLOOR() won't help if he's literally attempting to determine the difference in the underlying data types rather than simply trying to determine whether or not a value can be evaluated as an integer.
October 27, 2011 at 2:59 pm
JonFox (10/27/2011)
@bitbucket I guess it depends on what Walton is actually trying to do. I was assuming that for his purposes 13 and 13.0 were equivalent; that very well may have been a faulty assumption on my part though. You're absolutely correct that FLOOR() won't help if he's literally attempting to determine the difference in the underlying data types rather than simply trying to determine whether or not a value can be evaluated as an integer.
My purpose was to just give the OP a heads up on the limitations of FLOOR in this particular case, so that he does not go using it in a willy nilly fashion in other situations.
October 27, 2011 at 3:09 pm
Oh absolutely, it was an excellent thing to point out. Thanks!
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply