MSSQL SQL Server avoids the 0 error sharing method

Source: Internet
Author: User
Tags mssql

Excerpt from:http://www.maomao365.com/?p=6612

Summary:
In SQL Server, SQL scripts are described below to avoid the sharing of methods with the exception of 0 errors

In the development of various business systems, there are usually zero-error errors, and two processing methods are shared below:
Method 1:case when End
Declare @a int ---MolecularDeclare @b int ---DenominatorSelect   Case   when @b=0  Then NULL Else @a/@b End   as [a divided by B]
Method 2:nullif
Nullif (expression A, expression B)
--Returns the expression a if the expression A is not equal to expression B
--Returns NULL instead

Declare @a int -- -Molecular Declare @b int -- -Denominator Select @a / Nullif (@b,0as[a divided by B]

MSSQL SQL Server avoids the 0 error sharing method

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.