SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 comparing smallint and tinyint
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

natas
Yak Posting Veteran

51 Posts

Posted - 06/14/2005 :  04:35:19  Show Profile  Reply with Quote
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

Slovenia
11750 Posts

Posted - 06/14/2005 :  04:46:19  Show Profile  Visit spirit1's Homepage  Reply with Quote
not really...

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

natas
Yak Posting Veteran

51 Posts

Posted - 06/14/2005 :  12:20:27  Show Profile  Reply with Quote
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

Slovenia
11750 Posts

Posted - 06/14/2005 :  12:40:51  Show Profile  Visit spirit1's Homepage  Reply with Quote
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
Flowing Fount of Yak Knowledge

USA
6062 Posts

Posted - 06/14/2005 :  13:10:58  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000