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

convert bigint to int Expand / Collapse
Author
Message
Posted Wednesday, December 31, 2008 12:05 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Sunday, February 15, 2009 10:23 PM
Points: 14, Visits: 56
I have two variables @sar delared as bigint and @deep declared as int
I want to convert bigint to int. That is value of @sar to int.
Is this possible ? If yes How?
Post #627845
Posted Wednesday, December 31, 2008 12:42 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Wednesday, October 29, 2014 3:41 AM
Points: 407, Visits: 79
Your Question is not clear

I think you want to do this

declare @sar bigint
declare @deep int
set @sar = 1234356
set @deep = 12
select convert(int,@sar)
select @deep

Regards,

Yousaf Khan
Post #627865
Posted Wednesday, December 31, 2008 12:45 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, June 8, 2011 1:13 AM
Points: 48, Visits: 210
The bigint data type is supported where integer values are supported. However, when we are passing the bigint value to integer values, if the value exceeds the integer range it can't assing the bigint value to int.

declare @sar bigint
declare @deep int
begin
set @sar=3000000
set @deep =@sar
select @deep
end

here it will not throw any error, since the int range is not exceeded.

declare @sar bigint
declare @deep int
begin
set @sar=3000000000
'here it will throw the error.
set @deep =convert(int,@sar/1000)
select @deep
end

Nandy
Post #627868
Posted Wednesday, December 31, 2008 1:41 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Wednesday, October 29, 2014 3:41 AM
Points: 407, Visits: 79
Dear I think there no such way to convert value from bigint to int
the only way to change the datatype of int variable to bigint
@Deep bigint

If there is any then please post it.


Regards,

Yousaf Khan
Post #627885
Posted Wednesday, December 31, 2008 2:42 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, November 20, 2014 3:44 AM
Points: 1,260, Visits: 3,424
Interesting here... I think that you cannot convert from bigint to int if the range is exceeded otherwise from int to bigint I try and it works!

There is the ranges for the numeric datatypes:

bigint     -2^63 (-9,223,372,036,854,775,808) to 2^63-1 (9,223,372,036,854,775,807)

int -2^31 (-2,147,483,648) to 2^31-1 (2,147,483,647)

smallint -2^15 (-32,768) to 2^15-1 (32,767)

tinyint (0 to 255)



============================================================
SELECT YOUR PROBLEM FROM SSC.com WHERE PROBLEM DESCRIPTION =
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Post #627910
Posted Wednesday, December 31, 2008 2:42 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Sunday, February 15, 2009 10:23 PM
Points: 14, Visits: 56
Thanks yaar ......
I tried it like that but it throws an error when int range limit is exceeded
Post #627911
Posted Wednesday, December 31, 2008 3:25 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, September 23, 2014 8:08 AM
Points: 2,365, Visits: 1,846
if your bigint value exceeds the maximum value for int then its not possible to convert.

"Keep Trying"
Post #627927
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse