In SQL Server, if bigint is converted to int, an error is returned. How can this problem be solved? sqlserverbigint
One requirement is to store multiple statuses (including exceptions and warning statuses that can exist at the same time) in the Status values of one cloudmonitor) the bitwise operation mechanism is used to store data in an int type.
Currently, the monitoring log data volume is very large (hundreds of millions of data records) and data needs to be aggregated hourly and daily for online reports.
The status is divided into three levels: normal (0), warning (1), and exception (2). max must be used to select the worst state for aggregation, you need to add the level and number of status bits to process the status value. You need to use the bigint type for calculation,
The problem is that when you convert bigint to int to get the original status value, SQLServer reports an error:
Message 8115, level 16, status 2, 1st rows
An Arithmetic overflow error occurs when you convert an expression to an int type.
Because 0x80000000 has been used in the status code, the symbol bit problem occurs.
I wrote a conversion function to solve the problem.
Create function [dbo]. [BigintToInt] (@ Value bigint) RETURNS intASBEGIN -- whether int symbol bits exist IF @ Value & 0x80000000 <> 0 RETURN @ Value & 0 xFFFFFFFF | 0xffffffffff00000000 -- RETURN @ Value & 0 xFFFFFFFFEND
Which is the maximum value of int and bigint types in SQL server?
The smallest mutual number is the small value of the line.
An error occurred while converting SQL Server statements from nvarchar to bigint.
The value of fields connecting the two tables for the joint query should be the same. Your conID is the same as that of the second table. userID AS varchar (50), the two are not of the same type, it is better to change to the same, the problem is here.