SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


convert bigint to int


convert bigint to int

Author
Message
sar_kan25
sar_kan25
Grasshopper
Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)

Group: General Forum Members
Points: 24 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?Hehe
Yousaf Khan
Yousaf Khan
SSC-Addicted
SSC-Addicted (463 reputation)SSC-Addicted (463 reputation)SSC-Addicted (463 reputation)SSC-Addicted (463 reputation)SSC-Addicted (463 reputation)SSC-Addicted (463 reputation)SSC-Addicted (463 reputation)SSC-Addicted (463 reputation)

Group: General Forum Members
Points: 463 Visits: 113
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
Nandy
Nandy
SSC-Enthusiastic
SSC-Enthusiastic (104 reputation)SSC-Enthusiastic (104 reputation)SSC-Enthusiastic (104 reputation)SSC-Enthusiastic (104 reputation)SSC-Enthusiastic (104 reputation)SSC-Enthusiastic (104 reputation)SSC-Enthusiastic (104 reputation)SSC-Enthusiastic (104 reputation)

Group: General Forum Members
Points: 104 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
Yousaf Khan
Yousaf Khan
SSC-Addicted
SSC-Addicted (463 reputation)SSC-Addicted (463 reputation)SSC-Addicted (463 reputation)SSC-Addicted (463 reputation)SSC-Addicted (463 reputation)SSC-Addicted (463 reputation)SSC-Addicted (463 reputation)SSC-Addicted (463 reputation)

Group: General Forum Members
Points: 463 Visits: 113
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
Dugi
Dugi
SSCrazy
SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)

Group: General Forum Members
Points: 2150 Visits: 3511
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)



w00t

============================================================
SELECT YOUR PROBLEM FROM SSC.com WHERE PROBLEM DESCRIPTION =
http://www.sqlservercentral.com/articles/Best+Practices/61537/
sar_kan25
sar_kan25
Grasshopper
Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)

Group: General Forum Members
Points: 24 Visits: 56
Thanks yaar ......
I tried it like that but it throws an error when int range limit is exceeded
ChiragNS
ChiragNS
Hall of Fame
Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)

Group: General Forum Members
Points: 3387 Visits: 1865
if your bigint value exceeds the maximum value for int then its not possible to convert.

"Keep Trying"
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search