In SQL Server, if bigint is converted to int, an error is returned. How can this problem be solved? sqlserverbigint

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.