Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 comparing smallint and tinyint

Author  Topic 

natas
Yak Posting Veteran

51 Posts

Posted - 2005-06-14 : 04:35:19
Hello

DECLARE @littlenumber tinyint
DECLARE @biggernumer smallint

SET @littlenumber=20
SET @biggernumber=30

IF(@littlenumber>@biggernumber)
BEGIN
SELECT 'the littlenumber is bigger'
END


What i would like to know if it mather what type of "integer" it is.
If it makes a difference?. Does it have to be the same datatype when you do comparison?.

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-06-14 : 04:46:19
not really...

Go with the flow & have fun! Else fight the flow
Go to Top of Page

natas
Yak Posting Veteran

51 Posts

Posted - 2005-06-14 : 12:20:27
So it doesnt mather at all if i compare tinyint and smallints?, there can not be any errors?
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-06-14 : 12:40:51
what error do you expect?? it's just number comparison:

DECLARE @littlenumber tinyint
DECLARE @biggernumber smallint

SET @littlenumber = 25
--SET @littlenumber = 300 -- this returns an overflow error
SET @biggernumber = 500

IF(@littlenumber > @biggernumber)
SELECT 'the littlenumber is bigger'

IF(@littlenumber < @biggernumber)
SELECT 'the littlenumber is lower'

IF(@littlenumber = @biggernumber)
SELECT 'numbers equal'

IF(@littlenumber <> @biggernumber)
SELECT 'numbers not equal'


Go with the flow & have fun! Else fight the flow
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2005-06-14 : 13:10:58
The difference between the 2 datatypes is one of storage size and possible value range.

tinyint is 1 byte with possible values of 0 to 255
smallint is 2 bytes with possible values of -32768 to 32767

sql server will handle implicit conversions (when necessary) for performing comparisons.

Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -